JGuizard
3/24/2017 - 12:00 PM

Time and date utils

Time and date utils

#GET DATETIME AS STRING
from time import strftime
print (strftime("%d/%m/%Y %H:%M:%S"))
print (strftime("%d/%m/%Y %I:%M:%S")) #12h format

#GENERATE RANGE OF DATETIME
import datetime
base = datetime.datetime.today()
date_list = [base - datetime.timedelta(days=x) for x in range(0, 7)]  
for date in date_list:
  print(date.strftime("%Y-%m-%d %H:%M:%S"))