0% found this document useful (0 votes)
2 views1 page

Additional Date Module in Python

The document explains two methods in Python's datetime module: strftime() and strptime(). strftime() formats datetime objects into readable strings using specified format codes, while strptime() creates datetime objects from string representations of dates and times. Both methods utilize similar format codes for year, month, day, hour, minute, second, and AM/PM designations.

Uploaded by

saiyannsic20
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
2 views1 page

Additional Date Module in Python

The document explains two methods in Python's datetime module: strftime() and strptime(). strftime() formats datetime objects into readable strings using specified format codes, while strptime() creates datetime objects from string representations of dates and times. Both methods utilize similar format codes for year, month, day, hour, minute, second, and AM/PM designations.

Uploaded by

saiyannsic20
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 1

Additional Date Module in Python

I. strftime() is a method in Python's datetime module that stands for "string format time." It is
used to format datetime objects into readable strings based on specified format codes. This
method allows you to convert a datetime object into a string representation that can be
customized according to your needs.
Syntax: datetime_object.strftime(format)
Here are some commonly used format codes with strftime():
• %Y: Year with century as a decimal number (e.g., 2023).
• %y: Year without century as a zero-padded decimal number (e.g., 23 for 2023).
• %m: Month as a zero-padded decimal number (01 to 12).
• %B: Full month name (e.g., January, February).
• %b: Abbreviated month name (e.g., Jan, Feb).
• %d: Day of the month as a zero-padded decimal number (01 to 31).
• %A: Full weekday name (e.g., Monday, Tuesday).
• %a: Abbreviated weekday name (e.g., Mon, Tue).
• %H: Hour (00 to 23).
• %I: Hour (01 to 12).
• %M: Minute (00 to 59).
• %S: Second (00 to 59).
• %p: AM or PM.
II. strptime() is a method in Python's datetime module that stands for "string parse time." It is used
to create a datetime object from a string representation of a date and/or time, based on a
specified format. This method is particularly useful when you have date and time information in
string format and you want to convert it into a datetime object for further manipulation or
calculations.
Syntax: datetime.strptime(date_string, format)
Here are some commonly used format codes with strptime():
• %Y: Year with century as a decimal number (e.g., 2023).
• %y: Year without century as a zero-padded decimal number (e.g., 23 for 2023).
• %m: Month as a zero-padded decimal number (01 to 12).
• %d: Day of the month as a zero-padded decimal number (01 to 31).
• %H: Hour (00 to 23).
• %I: Hour (01 to 12).
• %M: Minute (00 to 59).
• %S: Second (00 to 59).
• %p: AM or PM.
• %B: Full month name (e.g., January).
• %b: Abbreviated month name (e.g., Jan).

You might also like