-
Notifications
You must be signed in to change notification settings - Fork 0
/
days_diff.py
30 lines (22 loc) · 911 Bytes
/
days_diff.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# Program is to calculate the number of days between given date string and the present day.
# Installed Module : pytz
# pip install pytz
import datetime
import pytz
def str_to_datetime(ts):
fmt = '%Y-%m-%d %H:%M:00'
return datetime.datetime.strptime(ts, fmt)
def time_now():
now_utc = datetime.datetime.utcnow()
local_tz = pytz.timezone('Asia/Kolkata') # Local timezone which we want to convert the UTC time
now_utc = pytz.utc.localize(now_utc) # Add timezone information to UTC time
x = now_utc.astimezone(local_tz) # Convert to local time
timestamp_in_str = x.strftime('%Y-%m-%d %H:%M:00')
timestamp_in_datetime = datetime.datetime.strptime(timestamp_in_str, '%Y-%m-%d %H:%M:00')
return timestamp_in_datetime
if __name__ == "__main__":
rt = '2022-02-28 00:05:00'
tday = time_now()
rt_dts = str_to_datetime(rt)
t1 = tday-rt_dts
print(t1.days)