dates in python

dates in python

>>>from datetime import date
>>>now = date.today()
>>>now
datetime.date(2003, 12, 2)
>>>now.strftime("%m-%d-%y. %d %b %Y is a %A on the %d day of %B.")
'12-02-03. 02 Dec 2003 is a Tuesday on the 02 day of December.'

Let's break down the format string used in the strftime() method:

%m: Represents the month as a zero-padded decimal number (e.g., "01" for January).
%d: Represents the day of the month as a zero-padded decimal number (e.g., "01" for the 1st day).
%y: Represents the year without the century as a zero-padded decimal number (e.g., "21" for 2021).
%b: Represents the abbreviated month name (e.g., "Jan" for January).
%Y: Represents the year with the century as a decimal number (e.g., "2021").
%A: Represents the full weekday name (e.g., "Monday").
%B: Represents the full month name (e.g., "January").

The actual output will depend on the current date and time when the code is executed.

To remember the meanings of the format strings */

%m (month): Remember it as "m" for month. It represents the month as a zero-padded decimal number.

%d (day): Think of "d" as the initial letter of "day." It represents the day of the month as a zero-padded decimal number.

%y (year): Associate it with the last two digits of the year. The lowercase "y" suggests a shorter representation of the year without the century.

%b (month abbreviation): Recall it as "b" for "abbreviation." It represents the abbreviated month name, such as "Jan" for January.

%Y (year with century): The uppercase "Y" indicates a four-digit representation of the year, including the century.

%A (weekday): Think of "A" as the initial letter of "weekday." It represents the full weekday name, such as "Monday."

%B (month): Remember it as "B" for the full "month" name. It represents the full month name, such as "January."

Additionally, you can create mnemonic phrases or sentences using the format strings to help you remember their meanings.

For example:

"May is month number %m."
"On the %d day, remember 'd' for day."
"Year with century: %Y is complete."
"Month abbreviation: %b, like 'b' for brief."
"Weekday is %A, the whole day."
"Full month name: %B, 'B' for big."S