Reputation: 2776
I'm currently doing a query to try and find the total number of customers between yesterday's utc0 and todays utc0, for some reason though it returns customers made the first hour or so after utc0
import stripe
from datetime import datetime, timedelta
stripe.api_key = app_config.STRIPE_KEY['secret_key']
yesterday_utc = datetime.utcnow().replace(hour=0, minute=0, second=0, microsecond=0) - timedelta(1)
today_utc = datetime.utcnow().replace(hour=0, minute=0, second=0, microsecond=0)
print(len(stripe.Customer.list(created={"gte":yesterday_utc, "lte":today_utc})['data']))
Not sure if I'm calling the wrong utc time, but this returns the customers made yesterday + the ones that where made immediately after the reset of the UTC day
Upvotes: 0
Views: 35
Reputation: 17533
datetime.utcnow()
returns the current timestamp in UTC, but you then replace the "hour-minute-second" part of the timestamp with zeroes. That's not the same thing as computing the timestamp for midnight UTC.
See this StackOverflow answer for how to reliably compute timestamps for midnight UTC depending on your timezone: https://stackoverflow.com/a/381788/5307473.
Keep in mind that Stripe's API expects UNIX timestamps, so you should call .strftime('%s')
on your datetime
instances to convert them to UNIX timestamps.
Upvotes: 1