TheShed

Python DateTime

Category: Programming
#Python #Dates

A fragment for formatting dates and time in Python:

import datetime
date = datetime.datetime.now()
sDate = date.strftime("%Y%m%d")
sDateTime =  date.strftime("%Y%m%d %H:%M:%S")

See see https://docs.python.org/2/library/datetime.html#strftime-and-strptime-behavior for formatting for details of string formatting for dates and times.