Definition:
If you want to generate the current date and time, you can use the datetime module.
It generates the current date and time using the now() function.
Now you will clearly understand the code logic with the help of the flowchart.
Datetime Module Flowchart :
Start ↓ You write program and import datetime module import datetime ↓ Python loads datetime module ↓ datetime module handles date and time ↓ You call function datetime.datetime.now() ↓ Module gets current date and time from system ↓ Result generated ↓ You store it in variable now = datetime.datetime.now() ↓ You print result print(now) ↓ Output shown 2026-04-20 10:30:00 ↓ End
Syntax:
import datetime
Example:
import datetime
now = datetime.datetime.now()
print(now)
Output:
Exercise
Use datetime module to print current date and time using Python.
