In order to convert a string to DateTime object we will make use of the datetime module that supplies classes for manipulating dates and times.
from datetime import datetime
Next we make use of the date.strftime(string, format) method to get a string representation of the date string.
datetime.strptime('26 March 2023 1:00 AM', '%d %B %Y %I:%M %p')
Let's take a look at an example,
from datetime import datetime
str_date = '26 March 2023 1:00 AM'
date_format_str = '%d %B %Y %I:%M %p'
date_time_object = datetime.strptime(str_date, date_format_str)
print(date_time_object)
Output:
2023-03-26 01:00:00

Reference: https://docs.python.org/3/library/datetime.html#module-datetime
Have Questions? Post them here!
- tkinter - Hello World! Program
- How to install Python Specific version (3.8, 3.9 or 3.10) using Brew
- How to install SpaCy (NLP Library) on Mac
- Python matplotlib segmentation fault: 11 macOS Big Sur
- How to uninstall pip Python packages
- 3 Ways to find if element is present in a List in Python
- How to Convert Python String to DateTime Object
- Python f-strings Formatted String Literals Syntax and Examples
- Where does brew install python in macOS
- Take input argument from command line in Python Programming
- Advanced print() Function Tutorial and Techniques for Python Developers
- How to add borders to tkinter label text
- Whats new in Python 3.10 Pre-release
- Float built-in function in Python
- List of All 35 Reserved Keywords in Python Programming Language 3.11
- How to check if Key Exists in Python Dictionary?
- Read a file line by line in Python Program
- ModuleNotFoundError: No module named qdarkstyle.colorsystem [Python]
- What is the Max and Minimum Value of int type in Python?
- What is Terminal Velocity and its Formula? How to calculate it programmatically?
- Fix: TypeError: can only concatenate str (not int) to str in Python
- How to take user input from the console in a Python program
- [Fix] TypeError: str object is not callable in Python
- 3 Python program to add two numbers
- How to delete a file using Python code example
- Fix Error CAA50021 - Number of retry attempts exceeds expectation - Microsoft 365 Apps - Microsoft
- Java 8 JDBC: Insert Timestamp Code Example - Java
- Install Visual Studio VS Code on Mac using Brew - MacOS
- Enable and reduce background noise in Microsoft Teams with AI-based noise suppression - Teams
- Using Java 8 Month Enum with Examples - Java
- Android Studio 1.3 beta now Available for Developers - Android-Studio
- How to Change Eclipse Default Web Browser - Eclipse
- Fix: Git Pull Error: unable to resolve reference refs/remotes/origin/master: reference broken - Git