Skip to content

Instantly share code, notes, and snippets.

@tkmru
Created December 15, 2013 22:12
Show Gist options
  • Select an option

  • Save tkmru/7978918 to your computer and use it in GitHub Desktop.

Select an option

Save tkmru/7978918 to your computer and use it in GitHub Desktop.
This is easy way to get date and datetime. It use str().
>>> from datetime import datetime
>>> now = datetime.now()
>>> now.strftime('%Y-%m-%d %H:%M:%S') #hard
'2013-10-06 07:59:20'
>>> str(now)
'2013-10-06 07:59:20.532184'
>>> str(now).split('.')[0] #easy
'2013-10-06 07:59:20
>>> from datetime import date
>>> today = date.today()
>>> today.strftime('%Y-%m-%d') #hard
'2013-10-06'
>>> str(today) #easy
'2013-10-06'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment