`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
9
votes
3 answers
Datetime strptime in Python pandas : what's wrong?
import datetime as datetime
datetime.strptime('2013-01-01 09:10:12', '%Y-%m-%d %H:%M:%S')
produces
AttributeError Traceback (most recent call
last) in ()
1 import datetime as datetime
----> 2…

Fagui Curtain
- 1,867
- 2
- 19
- 34
9
votes
2 answers
Extracting time from character string with strptime() in R, returning NA
I am trying to extract out the time from a character string in R and can't stop getting NA as a result. I have tried numerous variations of the regular expression tags, but can't seem to get around this simple problem. Any help/clarifications are…

stokeinfo
- 135
- 1
- 2
- 8
9
votes
2 answers
Colon in date format between seconds and milliseconds. How to parse in R?
How can I parse this date format? Should I change this colon to dot or maybe someone know better solution?
> x <- "2012.01.15 09:00:02:002"
> strptime(x, "%Y.%m.%d %H:%M:%S:%OS")
[1] "2012-01-15 09:00:02"
> strptime(x, "%Y.%m.%d %H:%M:%OS")
[1]…

Dorian Mejer
- 115
- 1
- 5
8
votes
7 answers
datetime.strptime(‘2017-01-12T14:12:06.000-0500’,'%Y-%m-%dT%H:%M:%S.%f%Z')
I've been trying to convert this specific date format to a string in Python like so:
datetime.strptime(‘2017-01-12T14:12:06.000-0500’,'%Y-%m-%dT%H:%M:%S.%f%Z')
But it doesn't work.
What am I doing wrong?

mrjextreme6
- 143
- 1
- 2
- 5
8
votes
1 answer
using strptime converting string to time but getting garbage
I have a problem with using strptime() function in c++.
I found a piece of code in stackoverflow like below and I want to store string time information on struct tm. Although I should get year information on my tm tm_year variable, I always get a…

caesar
- 2,865
- 11
- 29
- 36
8
votes
3 answers
python convert datetime formatted string to seconds
I am trying to decode a date string to epoch but I have difficulties getting the timezone. This is the last modified date from Amazon S3 keys.
time.strptime(key.last_modified, '%Y-%m-%dT%H:%M:%S.%Z')
ValueError: time data…

Vame
- 2,033
- 2
- 18
- 29
8
votes
2 answers
Using strptime %z with special timezone format
I am working with .csv data that was exported from Teradata. Several columns were originally timestamps with timezones, so after loading the .csv in R I'd like to convert these columns (which are loaded as strings) to POSIXlt or POSIXct. I am…

dnlbrky
- 9,396
- 2
- 51
- 64
7
votes
1 answer
In R, why do I get one millisecond difference between POSIXct and POSIXlt?
This snippet
options(digits.secs=3)
s<-"12:00:00.188"
fmt<-"%I:%M:%OS"
print(strptime(s,fmt))
print(as.POSIXct(strptime(s,fmt)))
gives this textual output:
[1] "2017-09-12 00:00:00.188 CEST"
[1] "2017-09-12 00:00:00.187 CEST"
while I expect the…

Alessandro Jacopson
- 18,047
- 15
- 98
- 153
7
votes
1 answer
Getting an error "number of items to replace is not a multiple of replacement length"
I'm trying to convert a record into a date and time format using the strptime function. However, I'm not sure why I'm getting the error:
number of items to replace is not a multiple of replacement length.
I tried to check the length of the record…

dixi
- 680
- 1
- 13
- 27
7
votes
2 answers
Combining a parsed time with today's date in Python
This should be easy, but as ever Python's wildly overcomplicated datetime mess is making simple things complicated...
So I've got a time string in HH:MM format (eg. '09:30'), which I'd like to turn into a datetime with today's date. Unfortunately…

lambshaanxy
- 22,552
- 10
- 68
- 92
7
votes
1 answer
Python ImportError for strptime in spyder for windows 7
I can't for the life of me figure out what is causing this very odd error.
I am running a script in python 2.7 in the spyder IDE for windows 7. It uses datetime.datetime.strptime at one point. I can run the code once and it seems fine (although I…

Thursdays Coming
- 1,002
- 13
- 28
6
votes
2 answers
Is there a wildcard format directive for strptime?
I'm using strptime like this:
import time
time.strptime("+10:00","+%H:%M")
but "+10:00" could also be "-10:00" (timezone offset from UTC) which would break the above command. I could use
time.strptime("+10:00"[1:],"%H:%M")
but ideally I'd find it…

citronic
- 9,868
- 14
- 51
- 74
6
votes
4 answers
Placing the grid along date tickmarks
I have the following data:
x=strptime(20010101:20010110)
y=1:10
z=data.frame(x,y)
So my data is this:
x y
1 2001-01-01 1
2 2001-01-02 2
3 2001-01-03 3
4 2001-01-04 4
5 2001-01-05 5
6 2001-01-06 6
7 2001-01-07 7
8 …

thequerist
- 1,774
- 3
- 19
- 27
6
votes
2 answers
Milliseconds puzzle when calling strptime in R
options(digits.secs = 3);
> strptime("2007-03-30 15:00:00.007", format = "%Y-%m-%d %H:%M:%OS");
[1] "2007-03-30 15:00:00.007"
> strptime("2007-03-30 15:00:00.008", format = "%Y-%m-%d %H:%M:%OS");
[1] "2007-03-30 15:00:00.008"
> strptime("2007-03-30…

sunt
- 303
- 2
- 5
- 12
6
votes
0 answers
Why does strptime result in an infinite list when using View in RStudio?
Disclaimer: The title of the question might be wrong, because I don't know what causes this behaviour. The 'issue' is that viewing a POSIXlt object in RStudio viewer shows an infinite linked list, as far as I can determine.
MWE:
x <-…

marts
- 658
- 1
- 10
- 15