python from string to datetime code example
Example 1: convert into date python
date_str = '09-19-2018'
date_object = datetime.strptime(date_str, '%m-%d-%Y').date()
print(type(date_object))
print(date_object)
Example 2: string to datetime convert
import datetime
date_time_str = '2018-06-29 08:15:27.243860'
date_time_obj = datetime.datetime.strptime(date_time_str, '%Y-%m-%d %H:%M:%S.%f')
print('Date:', date_time_obj.date())
print('Time:', date_time_obj.time())
print('Date-time:', date_time_obj)
Example 3: convert str to datetime
import datetime
datetime.datetime.strptime('Apr 2, 2019', '%b %d, %Y').strftime('%a, %d %b %Y')
Example 4: python string to datetime python
from dateutil import parser
datetime_object = parser.parse("Jun 1 2020 1:36PM")
Example 5: c# string to datetime
.Net str to DateTime