Created
January 30, 2018 20:06
Format a string using datetime parts in python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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