I assume I have import datetime before running each of the lines of code below
datetime.datetime.strptime("2013-1-25", '%Y-%m-%d').strftime('%m/%d/%y')
prints "01/25/13".
If you can't live with the leading zero, try this:
dt = datetime.datetime.strptime("2013-1-25", '%Y-%m-%d')
print '{0}/{1}/{2:02}'.format(dt.month, dt.day, dt.year % 100)
This prints "1/25/13".
EDIT: This may not work on every platform:
datetime.datetime.strptime("2013-1-25", '%Y-%m-%d').strftime('%m/%d/%y')
Answer from eumiro on Stack Overflow Top answer 1 of 2
302
I assume I have import datetime before running each of the lines of code below
datetime.datetime.strptime("2013-1-25", '%Y-%m-%d').strftime('%m/%d/%y')
prints "01/25/13".
If you can't live with the leading zero, try this:
dt = datetime.datetime.strptime("2013-1-25", '%Y-%m-%d')
print '{0}/{1}/{2:02}'.format(dt.month, dt.day, dt.year % 100)
This prints "1/25/13".
EDIT: This may not work on every platform:
datetime.datetime.strptime("2013-1-25", '%Y-%m-%d').strftime('%m/%d/%y')
2 of 2
31
If you can live with 01 for January instead of 1, then try...
d = datetime.datetime.strptime("2013-1-25", '%Y-%m-%d')
print datetime.date.strftime(d, "%m/%d/%y")
You can check the docs for other formatting directives.
What's a quick way to convert a date time stamp into RFC 822 format?
Use datetime.datetime.strptime to convert your string to a datetime object, then use the strftime method on that object to get the result you want. Check this handy site for the formatting strings: http://strftime.org/ More on reddit.com
Trying to convert from 18-digit LDAP/FILETIME format to human readable
You can convert this to a UNIX timestamp with: offset=$((134774*24*60*60)) # number of days from Jan 1, 1601 to Jan 1, 1970, converted to seconds timestamp=131159832017796720 # you would read this from the file unixTimestamp=$((timestamp/10000000-offset)) # convert 100-nanosecond interval to second, adjust for offset date -d @$unixTimestamp # display that timestamp; specify a format with +%a%b%c or --rfc-2822 More on reddit.com
Dates showing up as 5 digit numbers
the 5 digit number is the date value, (0 is 1/1/1900, and increases by 1 each day) you'll need to change the text format inside the formula, try this: =IF(A2=A1,C1&", "&TEXT(B2,"mm/dd/yyyy"), B2) or if c1 is the date, change the text function to be around C1 instead. You can also adjust the "mm/dd/yyyy" to be how you want the date formatted. More on reddit.com
Unable to convert strings to datetime objects
I'll answer your question if you tell me which generator you used to come up with that user name.
More on reddit.comVideos
00:32
Formatting Dates in Python: Convert and Print with datetime |Python ...
00:54
How to convert a string into datetime format in Python - YouTube
08:49
#71 How to Change Date Time Format in Python | Python Tutorials ...
00:51
Format Datetime With String Formatting #python #code #programming ...
Python Tutorial: Convert Different Date Formats to Unique ...
09:49
How To Convert Datetime To String Python - YouTube
Stack Abuse
stackabuse.com โบ how-to-format-dates-in-python
How to Format Dates in Python
January 4, 2023 - You can now convert this date object to any other string format. Handling different separators is as easy as using them in the format string: from datetime import datetime str = '9-15-22' date_object = datetime.strptime(str, '%m-%d-%y') print(date_object) # 2022-09-15 00:00:00 ยท In this article, we studied how to format dates in Python.
DigitalOcean
digitalocean.com โบ community โบ tutorials โบ python-string-to-datetime-strptime
How To Convert a String to a datetime Object in Python | DigitalOcean
December 13, 2024 - 1. How to convert Python date string mm dd yyyy to datetime? To convert a date string in the mm dd yyyy format to a datetime object in Python, you can use the datetime.strptime method from the datetime module:
Programiz
programiz.com โบ python-programming โบ datetime โบ strftime
Python strftime() - datetime to string
Become a certified Python programmer. Try Programiz PRO! ... The strftime() method returns a string representing date and time using date, time or datetime object. The program below converts a datetime object containing current date and time to different string formats.
Adverity
docs.adverity.com โบ reference โบ 2-enrich โบ python-expressions-for-managing-dates โบ converting-dates-from-one-format-in-to-another.html
Converting dates from one format to another โ Adverity Documentation documentation
Enter the date format to convert using date placeholders. For example, the date 01-03-2022 (1 March 2022) is in the date format %d-%m-%Y. format_to_use - This is the new format for the dates. Enter the new date format using date placeholders. See the examples section below for a worked example.
W3Schools
w3schools.com โบ python โบ python_datetime.asp
Python Datetime
The method is called strftime(), and takes one parameter, format, to specify the format of the returned string: ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com ยท If you want to report an error, or if you want to make a suggestion, send us an e-mail: help@w3schools.com ยท HTML Tutorial CSS Tutorial JavaScript Tutorial How To Tutorial SQL Tutorial Python Tutorial W3.CSS Tutorial Bootstrap Tutorial PHP Tutorial Java Tutorial C++ Tutorial jQuery Tutorial
Medium
medium.com โบ @generativeai.saif โบ how-to-convert-a-string-to-a-date-in-python-complete-guide-for-2025-bd5ece07c57c
How to Convert a String to a Date in Python: Complete Guide for 2025 | by Saif Ali | Medium
April 6, 2025 - Notice how the space between the date and time must be included in the format string. Every character in the input string needs a corresponding element in the format pattern. After converting a string to a datetime object, you might need just the date or time component. Python makes this easy with the .date() and .time() methods:
Mimo
mimo.org โบ glossary โบ python โบ datetime
Python datetime Module: Working with Dates, Times, and Formatting
In this example, the string 2024-09-19 15:45:30 is converted into a datetime object using the format "%Y-%m-%d %H:%M:%S".
DataCamp
datacamp.com โบ tutorial โบ converting-strings-datetime-objects
Convert String to DateTime in Python: Complete Guide with Examples | DataCamp
June 8, 2018 - In Python, we can use the datetime.strptime() method to convert a string to a datetime object. The strptime() method takes two arguments: the string to be converted and a format string specifying the input string's format.
Progress
blog.ipswitch.com โบ date-formatting-in-python
Date Formatting using Python Datetime and Strptime
November 13, 2024 - The strptime() method allows you to pass in a simple string like 2/4/18 and a simple formatting string to define where the day, month and year is. >>> objDate = datetime.strptime(strDate, '%m/%d/%y') >>> objDate datetime.datetime(2018, 2, 4, 0, 0) Now that Python understands this string is an actual date, we can either leave it as-is or convert it back to a string in a different format.
Adverity
docs.adverity.com โบ reference โบ 2-enrich โบ python-expressions-for-managing-dates โบ converting-dates-from-one-format-in-to-another.htm
Converting dates from one format to another
Enter the date format to convert using date placeholders. For example, the date 01-03-2022 (1 March 2022) is in the date format %d-%m-%Y. format_to_use - This is the new format for the dates. Enter the new date format using date placeholders. See the examples section below for a worked example.
Pandas
pandas.pydata.org โบ docs โบ reference โบ api โบ pandas.to_datetime.html
pandas.to_datetime โ pandas 3.0.1 documentation - PyData |
The numeric values would be parsed as number of units (defined by unit) since this reference date. If 'unix' (or POSIX) time; origin is set to 1970-01-01. If 'julian', unit must be 'D', and origin is set to beginning of Julian Calendar. Julian day number 0 is assigned to the day starting at noon on January 1, 4713 BC. If Timestamp convertible (Timestamp, dt.datetime, np.datetimt64 or date string), origin is set to Timestamp identified by origin.
GeeksforGeeks
geeksforgeeks.org โบ python โบ converting-string-yyyy-mm-dd-into-datetime-in-python
Converting string into DateTime in Python - GeeksforGeeks
July 23, 2025 - ... Explanation: Here, we passed the date string '2023-07-25' to parse(). It automatically recognized the format and returned a full datetime object. datetime.strptime() method, part of Python's datetime module, efficiently converts a date string ...