`strptime` reads the time from the string s using the timeformat specifiers and converts it into seconds since the year 2000.
Questions tagged [strptime]
779 questions
217
votes
10 answers
Parse date string and change format
I have a date string with the format 'Mon Feb 15 2010'. I want to change the format to '15/02/2010'. How can I do this?

Nimmy
- 5,051
- 7
- 33
- 32
212
votes
5 answers
How can I account for period (AM/PM) using strftime?
Specifically I have code that simplifies to this:
from datetime import datetime
date_string = '2009-11-29 03:17 PM'
format = '%Y-%m-%d %H:%M %p'
my_date = datetime.strptime(date_string, format)
# This prints '2009-11-29 03:17 AM'
print…

Kenan Banks
- 207,056
- 34
- 155
- 173
155
votes
2 answers
How to convert a date string to different format
I need to convert date string "2013-1-25" to string "1/25/13" in python.
I looked at the datetime.strptime but still can't find a way for this.

Chamith Malinda
- 4,399
- 5
- 24
- 28
154
votes
8 answers
Get date from week number
Please what's wrong with my code:
import datetime
d = "2013-W26"
r = datetime.datetime.strptime(d, "%Y-W%W")
print(r)
Display "2013-01-01 00:00:00", Thanks.

Ali SAID OMAR
- 6,404
- 8
- 39
- 56
113
votes
8 answers
What are the "standard unambiguous date" formats for string-to-date conversion in R?
Please consider the following
$ R --vanilla
> as.Date("01 Jan 2000")
Error in charToDate(x) :
character string is not in a standard unambiguous format
But that date clearly is in a standard unambiguous format. Why the error message?
Worse, an…

Matt Dowle
- 58,872
- 22
- 166
- 224
95
votes
2 answers
How to parse milliseconds?
How do I use strptime or any other functions to parse time stamps with milliseconds in R?
time[1]
# [1] "2010-01-15 13:55:23.975"
strptime(time[1], format="%Y-%m-%d %H:%M:%S.%f")
# [1] NA
strptime(time[1], format="%Y-%m-%d %H:%M:%S")
# [1]…

signalseeker
- 4,100
- 7
- 30
- 36
72
votes
8 answers
Display Python datetime without time
I have a date string and want to convert it to the date type:
I have tried to use datetime.datetime.strptime with the format that I want but it is returning the time with the conversion.
when = alldates[int(daypos[0])]
print when, type(when)
then =…

pythonhunter
- 1,047
- 3
- 10
- 23
72
votes
5 answers
How to format date string via multiple formats in python
I have three date formats: YYYY-MM-DD, DD.MM.YYYY, DD/MM/YYYY.
Is it possible to validate and parse strings such as 2014-05-18 or 18.5.2014 or 18/05/2019?

Alexey Sh.
- 1,734
- 2
- 22
- 34
57
votes
9 answers
What does the "p" in strptime stand for?
There is a strptime function in many language libraries (C, Python, Ruby, PHP, PERL, etc.).
It seems to be based on the Open Group's specification for time.h.
I understand 'str' stands for string, and 'time' obviously stands for time, but what does…

Oddthinking
- 24,359
- 19
- 83
- 121
55
votes
4 answers
How to parse timezone with colon
Is there a way to parse timezone in "+00:00" format with datetime.strptime? For instance:
Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:43:06) [MSC v.1600 32 bit (In
tel)] on win32
Type "help", "copyright", "credits" or "license" for more…

dijxtra
- 2,681
- 4
- 25
- 37
54
votes
6 answers
How to remove unconverted data from a Python datetime object
I have a database of mostly correct datetimes but a few are broke like so: Sat Dec 22 12:34:08 PST 20102015
Without the invalid year, this was working for me:
end_date = soup('tr')[4].contents[1].renderContents()
end_date =…

Ben Keating
- 8,206
- 9
- 37
- 37
53
votes
6 answers
Parsing datetime strings containing nanoseconds
I have some log files with times in the format HH:MM::SS.nano_seconds (e.g. 01:02:03.123456789). I would like to create a datetime in python so I can neatly do math on the time (e.g. take time differences). strptime works well for microseconds using…

user1332148
- 1,256
- 2
- 11
- 24
43
votes
8 answers
Changing date format in R
I have some very simple data in R that needs to have its date format changed:
date midpoint
1 31/08/2011 0.8378
2 31/07/2011 0.8457
3 30/06/2011 0.8147
4 31/05/2011 0.7970
5 30/04/2011 0.7877
6 31/03/2011 0.7411
7 …

indigo
- 1,067
- 4
- 15
- 26
43
votes
3 answers
how to initialize time() object in python
I am trying to initialize a time object like this:
t = datetime.time(0,0,0)
but I am getting this error:
descriptor 'time' requires a 'datetime.datetime' object but received a 'int'
I have these things imported
import datetime
from datetime import…

Santiago
- 1,984
- 4
- 19
- 24
42
votes
5 answers
How to convert integer into date object python?
I am creating a module in python, in which I am receiving the date in integer format like 20120213, which signifies the 13th of Feb, 2012. Now, I want to convert this integer formatted date into a python date object.
Also, if there is any means by…

Uday0119
- 770
- 1
- 7
- 23