You can use the strftime
method of the datetime
object to get the year, month, and day individually.
Here's an example:
main.py248 chars14 lines
This will output:
main.py29 chars4 lines
You can format the strftime
argument according to your desired output format. In the example above, %Y
represents the year with century as a decimal number, %m
represents the month as a zero-padded decimal number, and %d
represents the day of the month as a zero-padded decimal number.
gistlibby LogSnag