Which module in Python is used to work with dates and times?
A
time B
datetime C
calendar D
dateutil
Analysis & Theory
`datetime` is the built-in module used for working with dates and times in Python.
What does `datetime.datetime.now()` return?
A
Current date only B
Current time only C
Current date and time D
Epoch time
Analysis & Theory
`datetime.now()` returns the current date and time as a `datetime` object.
What is the correct way to get the current year using `datetime`?
A
datetime.year() B
now.year() C
datetime.now().year D
datetime.current().year
Analysis & Theory
`datetime.now().year` returns the current year.
Which method is used to create a specific date?
A
date.create() B
datetime.make() C
datetime.date() D
date.make()
Analysis & Theory
`datetime.date(year, month, day)` creates a specific date object.
What is the output type of `datetime.date.today()`?
A
`str` B
`int` C
`datetime` D
`date`
Analysis & Theory
`date.today()` returns a `date` object representing the current local date.
What will `datetime.datetime(2025, 7, 1).strftime('%B')` return?
A
07 B
July C
7 D
Jul
Analysis & Theory
`%B` returns the full month name, so the result is 'July'.
What does `timedelta(days=5)` represent?
A
A time range of 5 hours B
A date object C
A difference of 5 days D
A time in the past
Analysis & Theory
`timedelta(days=5)` represents a duration or difference of 5 days.
How can you add 7 days to the current date?
A
date + 7 B
now.add(7) C
datetime.now() + timedelta(days=7) D
datetime.plus(7)
Analysis & Theory
Use `datetime.now() + timedelta(days=7)` to add 7 days.
What will `datetime.now().strftime('%Y-%m-%d')` return?
A
Only year B
Full timestamp C
Formatted date as string (e.g., '2025-07-01') D
Date object
Analysis & Theory
`strftime('%Y-%m-%d')` returns the date formatted as a string.
Which of these is the correct import to access `datetime` and `timedelta`?
A
`import datetime` B
`from datetime import datetime, timedelta` C
`from time import datetime, timedelta` D
`import date`
Analysis & Theory
To access both `datetime` and `timedelta`, use `from datetime import datetime, timedelta`.