I am given this 1974-11-27T00:00:00
but I don't know what you call this format so I can't find anything online on how to make this yyyymmdd
Asked
Active
Viewed 2,961 times
-2

mastercool
- 463
- 12
- 35
-
1Have you done any research on how to parse and convert date formats in Python, for example? – AMC Sep 18 '20 at 20:30
-
1Does this answer your question? [Parse date string and change format](https://stackoverflow.com/questions/2265357/parse-date-string-and-change-format) – AMC Sep 18 '20 at 20:31
5 Answers
3
That's called an ISO formatted date time string. You can turn that into a datetime object by just doing:
import datetime
example = '1974-11-27T00:00:00'
d = datetime.datetime.fromisoformat(example)
Now that's it's a date-time object, you can format it however you want:
print(d.strftime('%Y%m%d'))
>> 19741127

Doobeh
- 9,280
- 39
- 32
1
Assuming it's a string, you can replace the -
directly
s = '1974-11-27T00:00:00'
s = s[:10].replace('-','')

Rudi Strydom
- 4,417
- 5
- 21
- 30

Maciek Woźniak
- 346
- 2
- 10
0
To transform what you have into a date you can use python datetime
:
import datetime
this_date = '1974-11-27T00:00:00'
# transform the string you have to a datetime type
your_date = datetime.datetime.strptime(this_date, '%Y-%m-%dT%H:%M:%S')
# print it in the format you want to
print(your_date.strftime("%Y%m%d"))
19741127

Gozy4
- 444
- 6
- 11
0
Try this:
import datetime
str = '1974-11-27T00:00:00'
datetime.strptime(str,"%Y-%m-%dT%H:%M:%S")

SunilG
- 347
- 1
- 4
- 10
0
This date you have is in standard ISO 8601 format. To convert it into Python datetime
object (assuming you have string) run
from datetime import datetime
s = '1974-11-27T00:00:00'
d = datetime.fromisoformat(s)
Once its a proper datetime
instance you can format it anyway you want
print(d.strftime("%Y%m%d"))
19741127

Łukasz
- 127
- 1
- 5