`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
3
votes
2 answers
Why doesn't strptime() set tm_wday properly in this example?
I'm using strptime(3) to parse a string representing a date:
#include
#include
int main () {
struct tm t;
strptime("2015-04-19 12:00:00", "%F %T", &t); /* Sunday */
printf("%d\n", t.tm_wday); /* Should print 0 */
return…

lindelof
- 34,556
- 31
- 99
- 140
3
votes
0 answers
R datetime change from DST to GMT at 01:16 in the morning?
I've been learning how to use strptime() and time-zones date/times in genreal and I was interested to see how R handles the clocks changing from BST to GMT. I looked up a future date and read here that in 2019 the clocks go backwards from BST to GMT…

Holmestorm
- 93
- 7
3
votes
4 answers
How to parse e.g. 2010-04-24T07:47:00.007+02:00 with Python strptime
Does anyone know how to parse the format as described in the title using Pythons strptime method?
I have something similar to this:
import datetime
date = datetime.datetime.strptime(entry.published.text, '%Y-%m-%dT%H:%M:%S.Z')
I can't seem to…

PropellerHead
- 929
- 1
- 12
- 27
3
votes
1 answer
Handling integer times in R
Times in my data frame are recorded as integers as in: 1005,1405,745,1130,2030 etc. How do I convert these integers so R will understand and use it in functions such as strptime. Thanks in advance for your help

Mawriz
- 33
- 3
3
votes
1 answer
Python: AttributeError: 'str' object has no attribute 'datetime'
I am using this code:
def calcDateDifferenceInMinutes(end_date,start_date):
fmt = '%Y-%m-%d %H:%M:%S'
start_date_dt = datetime.strptime(start_date, fmt)
end_date_dt = datetime.strptime(end_date, fmt)
# convert to unix…

Jazzmine
- 1,837
- 8
- 36
- 54
3
votes
1 answer
create a list of datetime objects using datetime.strptime
I have a list of strings.
date_str = ["2012-11-04 1:05:21", "2013-11-03 1:05:21", "2014-11-02 1:07:31"]
I want to read them as datetime objects. For one string, I do
datetime.strptime(date_str[1], "%Y-%m-%d %H:%M:%S")
but I don't know how to…

asiehh
- 553
- 12
- 22
3
votes
1 answer
How to convert a string representing a time range into a struct_time object?
You can parse a string representing a time, in Python, by using the strptime method. There are numerous working examples on stackoverflow:
Converting string into datetime
However, what if your string represented a time range, as opposed to a…

Andrew Hardiman
- 929
- 1
- 15
- 30
3
votes
2 answers
Python and Strptime Difference When Variable Set or Read From File But Exact Same Value
Going for worlds worst title there but I can basically sum this weirdness up in one line.
This works fine:
dnow=datetime.datetime.now()
racetime = '2016-01-05 13:39:53.968000'
NewRaceTime = datetime.datetime.strptime(racetime, '%Y-%m-%d…

PoweredByCoffee
- 1,153
- 3
- 14
- 25
3
votes
1 answer
Convert value to time format in R
I have values in the format "221559460" where first two is hour, other two is minute and following digits are in milliseconds. Is there any shortcut method to convert to time-series format without manually appending ":" in the value and calculating…

Anish
- 1,920
- 11
- 28
- 48
3
votes
2 answers
Problem with strptime() - %p is not taken into account
I am trying to convert a date in a particular format using strptime, and i realized that the information about AM/PM is lost. Not sure why.
Here is the code.
struct tm t;
strptime("Wed 4/18/2007 4:28:22 PM", "%a %m/%d/%Y %H:%M:%S %p",…

AMM
- 17,130
- 24
- 65
- 77
3
votes
3 answers
From string to datetime with or without millisecond
I have a list of strings each of them represent a time with or without milliseconds, e.g.
l = ['03:18:45.2345', '03:19:23']
And I want to convert each string into a datetime object. Now I'm running:
>>> l = ['03:18:45.2345', '03:19:23']
>>> for…

rafforaffo
- 511
- 2
- 7
- 21
3
votes
1 answer
Is the specified behaviour of `strptime` defined if date is underspecified, overspecified or inconsistent?
I have not found any (or few) indications of the appropriate behaviour for strptime if the date is:
underspecified: contains not enough data to uniquely fill out tm (eg fx tail = strptime("%Y %p", "2015 p.m", &tm);)
inconsistent: contains possibly…

skyking
- 13,817
- 1
- 35
- 57
3
votes
1 answer
Why does strptime() behave differently on OSX and on Linux?
Consider this program:
#include
#include
int main() {
struct tm t;
strptime("2015-08-13 12:00:00", "%F %T", &t);
printf("t.tm_wday = %d\n", t.tm_wday);
return 0;
}
Under OSX, this is what I obtain:
$ gcc…

lindelof
- 34,556
- 31
- 99
- 140
3
votes
3 answers
how to use time.strptime for a file full of long format date
I am new to python and trying to learn how to read data files. I have a file with time stamps:
[2015-07-27T18:01:55.7647616+01:00 2015-07-27T18:01:55.7827840+01:00
2015-07-27T18:01:55.8142720+01:00 ..., 2015-07-27T18:04:05.3064192+01:00
…

edgarbc
- 366
- 2
- 15
3
votes
1 answer
Python datetime.strptime - Converting month in String format to Digit
I have a string that contains the date in this format:
full_date = "May.02.1982"
I want to use datetime.strptime() to display the date in all digits like: "1982-05-02"
Here's what I tried:
full_date1 = datetime.strptime(full_date, "%Y-%m-%d")
When…

Krithika Raghavendran
- 457
- 3
- 10
- 25