← Go Back
You can access the date values individually:
And the time values:
You might also use
How to Get the Current Date and/or Time
Thedatetime.datetime.now()
standard function returns the current date and time:>>> import datetime
>>> now = datetime.datetime.now()
>>> now
datetime.datetime(2023, 12, 28, 20, 1, 34, 419931)
You can access the date values individually:
>>> now.year
2023
>>> now.month
12
>>> now.day
28
And the time values:
>>> now.hour
20
>>> now.minute
1
>>> now.second
34
>>> now.microsecond
419931
You might also use
now.date()
or now.time()
to get the date or the time separately.🐍 You might also find interesting: