`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
2
votes
1 answer
Time::Piece strptime has trouble with %X
I'm trying to parse the following data using Time::Piece->strptime() in perl v5.26:
my $str = "Mon Feb 21 02:54:49 IST 2022";
my $time_zone = substr($str, 20, 3);
my $date_time = Time::Piece->strptime($str, "%a %b %e %X $time_zone %Y");
print…

Harsh Gupta
- 23
- 4
2
votes
1 answer
Weirdly enough, '#' is a bad directive in format '%#H:%M'
I've seen a lot of similar questions, and still I don't seem to be able find out what the issue with my code is.
I'm running this:
from datetime import datetime
date_st = "17:00"
date = datetime.strptime(date_st, "%#H:%M")
And I get the…

mykhailohoy
- 442
- 4
- 15
2
votes
3 answers
strptime() produces junk times in C
I tried using strptime() to parse dates in the ISO 8601 format (specified by "%F" or "%Y-%m-%d"), but when i read from the result struct tm i get absurd values for time, minutes and seconds.
Here is an example code and the result:
char *s_date =…

VoteAnthony
- 39
- 5
2
votes
1 answer
Calculate time difference between 2 timestamps in hours using R
I'm trying to obtain the time difference between 2 timestamps in hours.
I have the data:
ID Lat Long Traffic Start_Time End_Time
1 -80.424 40.4242 54 2018-01-01 01:00 2018-01-01 01:10
2 …

Reta
- 363
- 3
- 4
- 15
2
votes
4 answers
How can I parse a number of days that exceeds the length of a month?
I made a countdown function (which works just fine) that returns the time remaining as a string. I'm using the strptime and strftime functions to sort of parse the data so I could have a variable for how many days, hours, minutes and seconds that…

Daniel Frost
- 51
- 6
2
votes
5 answers
how to change datetimeindex to just contain date in python
I have a column called date with this values
> DatetimeIndex(['2014-02-19'], dtype='datetime64[ns]', freq=None)
> DatetimeIndex(['2013-02-29'], dtype='datetime64[ns]', freq=None)
> DatetimeIndex(['2018-04-15'], dtype='datetime64[ns]',…

rylynn_mcbos
- 49
- 5
2
votes
2 answers
Date comaprison in python attribute error
I have a date stored in a text file in this format "19 May 2021", I want to compare this date to the today's date to see if we have reached this date or not (> / <) comparisons. I was instructed to first convert this string date to a date object, I…

snlonline
- 47
- 5
2
votes
1 answer
Javascript strptime() is adding one month extra
From an Spring boot project we are calling GraalVM for processing some rules written in JavaScript. The GraalVM version is 'org.graalvm.sdk=1.0.0-rc11'. When we are using strptime(), it's adding one month extra. Like for the date 24/02/2021, it is…

Suvendu Ghosh
- 391
- 1
- 3
- 16
2
votes
3 answers
Unexpected behavior of python datetime strptime with zero-padded formats
I have list of strings representing datetimes in different formats. I.e.:
list_date_str = ['2021010112', '202101011210']
The first should translate to 2021-01-01 12:00, the second to 2021-01-01 12:10.
Without giving much thought to it I wrote this…

Durtal
- 1,063
- 3
- 11
2
votes
3 answers
ValueError: Unconverted data remains .000
I'm super new to Python and just got thrown for a loop when my source csv file changed its format. The date field now has this: 2020-07-22T00:00:00.000 when what I want is this: 2020-07-22.
I need to read the source csv and append it to a database…

vbdashes
- 23
- 1
- 4
2
votes
3 answers
%b vs %B in datetime module (python 3)
fmt_1 = '%a %d %B %Y %H:%M:%S %z'
fmt_2 = '%a %d %b %Y %H:%M:%S %z'
t1="Sat 14 Sep 2126 00:36:44 +1400"
code1= dateime.datime.strptime(t1,fmt_1) #run time error
code2= dateime.datime.strptime(t1,fmt_2) #right code
I got runtime error for fmt_1…

The Sky Peacock
- 21
- 1
- 2
2
votes
1 answer
strptime throws error when run in docker container
When I run
from datetime import datetime
print(datetime.strptime('2020-01-15 09:20:00.00+00:00', '%Y-%m-%d %H:%M:%S.%f%z'))
It prints out
2020-01-15 09:20:00+00:00
When I run a docker container with those exact same lines, it throws this…

cheesus
- 1,111
- 1
- 16
- 44
2
votes
2 answers
time data '2019-06-02T16:19:27.000-04:00' does not match format '%Y-%m-%dT%H:%M:%S.%fZ'
I am getting the error above when I do:
datetime.strptime(item['dt'], "%Y-%m-%dT%H:%M:%S.%fZ")
Even if I try:
datetime.strptime(item['dt'], "%Y-%m-%dT%H:%M:%S.%f")
I am getting unconverted data remains: -04:00 as my error.
What am I doing wrong?

nb_nb_nb
- 1,243
- 11
- 36
2
votes
1 answer
Cursor's iterate() method sometimes fails when converting a string to datetime
My goal is to fetch rows from Vertica that contain a column of type Timestamp with format YYYY-MM-DD HH:MM:SS, and do stuff with them.
My problem is that cursor.iterate() function sometimes throw an error, and I do not know why.
It is very…

Khalifa Badir
- 21
- 3
2
votes
2 answers
date functions in R return wrong year
I am trying to convert a character field into a date field for which the options are to either use strptime function or as.Date function. Here is two reproducible examples:
strptime(c("5/13/2015"),"%m/%d/%y")
#result is "2020-05-13…

seakyourpeak
- 531
- 1
- 6
- 18