Skip to content

Instantly share code, notes, and snippets.

@ZhongxuanWang
Created May 1, 2020 11:21
Show Gist options
  • Save ZhongxuanWang/56d6d6c695e8e266fd025b0bb29722e8 to your computer and use it in GitHub Desktop.
Save ZhongxuanWang/56d6d6c695e8e266fd025b0bb29722e8 to your computer and use it in GitHub Desktop.
python get the time between string dates
def get_time(**time):
time_now = datetime.now()
datetime_format = '%Y-%m-%d %H:%M'
time_now = datetime.strptime(time_now, datetime_format)
time_des = f"{time['year'] + time_now}-{time['month']}-{time['day']} {time['hour']}:{time['minute']}"
diff = time_now - datetime.strptime(time_des, datetime_format)
print("Difference:", diff)
print("Days:", diff.days)
print("Microseconds:", diff.microseconds)
print("Seconds:", diff.seconds)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment