I have situation where I should ignore the timestamp in a date string. I have tried the below command but with no luck.
"start" variable used below is in AbsTime (Ex: 01MAY2017 11:45) and not a string.
start_date = datetime.datetime.strptime(start, '%d%^b%Y').date()
print start_date
My output should be :
01MAY2017 or 01MAY2017 00:00
Could any one help me.
Your directives are slightly off, and you need to capture all the contents (irrespective of what you want to retain).
start_date = datetime.datetime.strptime(start, '%d%b%Y %H:%M').date()
print start_date.strftime('%d%b%Y')
# '01May2017'
Update - Adding complete code below:
import datetime
start = '01MAY2017 11:45'
start_date = datetime.datetime.strptime(start, '%d%b%Y %H:%M').date()
print start_date.strftime('%d%b%Y')
# 01May2017
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With