1 year ago
#347769
jayamani siddaiyan
How do i pass epoctime variable in postgresql query?
Hi I have a start and end epoctime(UNIX time stamp) values of a day stored in variable. How do i use these values in postgresql query to fetch one day data from db.
Code show below
today =datetime.datetime.now()
yesterday = today - timedelta(days=1)
start = yesterday.replace(hour=00, minute=0, second=0, microsecond=000000)
end = yesterday.replace(hour=23, minute=59, second=59, microsecond=000000)
print(f"start of the day {start}")
print(f"end of the day {end}")
#epoch Calculation
start_epoctime = int(time.mktime(start.timetuple()) + start.microsecond * 1e-6)*1000
end_epoctime = int(time.mktime(end.timetuple()) + end.microsecond * 1e-6)*1000
SELECT ccu_time,
where ccu_time between start_epoctime and end_epoctime
I need to pass variable bcz my start and end epoctime vary dynamically in daily basis.
if i directly pass numerical epoctime between 1648319400000 and 1648405799000 working fine
python
postgresql
epoch
0 Answers
Your Answer