Skip to content

Instantly share code, notes, and snippets.

@cbertolasio
Created January 30, 2018 20:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cbertolasio/f77d099fd8074e4b08dfe4838a143492 to your computer and use it in GitHub Desktop.
Save cbertolasio/f77d099fd8074e4b08dfe4838a143492 to your computer and use it in GitHub Desktop.
Format a string using datetime parts in python
#assuming the date is 25-JAN-2018 at 01:30:52
#the code below shouldPrint "AllPivots_20180125_0130"
from datetime import datetime
current = datetime.utcnow()
print(current)
year = str(current.year)
month = str(current.month).zfill(2)
day = str(current.day).zfill(2)
hours = str(current.hour).zfill(2)
minutes = str(current.minute).zfill(2)
fileName = "TableName_{year}{month}{day}_{hrs}{min}".format(year=year, month=month, day=day, hrs=hours, min=minutes)
print(fileName)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment