Questions tagged [strptime]

`strptime` reads the time from the string s using the timeformat specifiers and converts it into seconds since the year 2000.

779 questions
4
votes
1 answer

How to convert a specific integer to datetime in python

For example, I have the int 043017, which I want converted to 04/30/17 (April 30, 2017), I want to be able to convert any int of that format into datetime, how can this be accomplished?
Alex
  • 486
  • 1
  • 7
  • 19
4
votes
1 answer

How to handle microseconds with 7 decimal precision instead of 6

I am processing a csv in python (3.5) that has a date field in it. The date contains a microsecond precision of 7 rather than 6, which I believe is the max that strptime can handle. Without stripping the field the last character, is there a way…
mikebmassey
  • 8,354
  • 26
  • 70
  • 95
4
votes
2 answers

How Do I Parse a Date Time String That Includes Fractional Time?

I have a date time string: 20:48:01.469 UTC MAR 31 2016 I would like to convert this string representation of time to a struct tm using strptime, but my format string isn't working. Is there a format specifier for fractional seconds? Perhaps %S,…
Dr. Debasish Jana
  • 6,980
  • 4
  • 30
  • 69
4
votes
0 answers

PHP: `strptime()` alternative in Windows

My current PHP library doesn't work in Windows because strptime() function is not implemented in Windows. Note: This function is not implemented on Windows platforms. Source: http://php.net/manual/en/function.strptime.php Does anyone know any…
Aminah Nuraini
  • 18,120
  • 8
  • 90
  • 108
4
votes
1 answer

Python- strptime ValueError unconverted data remains: :00

I have a .csv file with a column that have dates which looks like "2/15/2016 1:44:00 PM",am running into following error with the code below...can anyone provide inputs on what is wrong? CODE:- import csv import datetime as dt import os File =…
user665997
  • 313
  • 1
  • 4
  • 18
4
votes
1 answer

Python Strptime Occasionally Missing Microseconds

I have data being passed in coming in with the format %Y-%m-%d %H:%M:%S.%f. So I work with the data based on that structure and once a blue moon something goes wrong. So I started dumping it out when something breaks and I noticed the microseconds…
PoweredByCoffee
  • 1,153
  • 3
  • 14
  • 25
4
votes
4 answers

How to convert character string in microseconds to struct tm in C?

I have a string that contains microseconds since the epoch. How could I convert it to a time structure? #include #include #include int main () { struct tm tm; char buffer [80]; char *str…
user1024718
  • 573
  • 6
  • 18
4
votes
1 answer

ValueError: time data '24:00' does not match format '%H:%M'

I'm having serious trouble converting 24 hour time to 12 hour. def standard_time(t): t = datetime.strptime(t, "%H:%M") return t When fed in '24:00' we get ValueError: time data '24:00' does not match format '%H:%M' I also attempt…
1Up
  • 994
  • 2
  • 12
  • 24
4
votes
1 answer

Speeding up datetime.strptime

I am using the following piece of code to extract a date from a string: try: my_date = datetime.strptime(input_date, "%Y-%m-%d").date() except ValueError: my_date = None If I run this 750,000 times, it takes 19.144 seconds (determined with…
physicalattraction
  • 6,485
  • 10
  • 63
  • 122
4
votes
2 answers

time.strptime() - argument 0 must be str, not bytes

Obviously I'm aware already that strftime and strptime doesn't like byte strings as parameters, however i'm in a pickle here because I sort of need to read a file content which has different character encodings saved in it and i need to handle them…
Torxed
  • 22,866
  • 14
  • 82
  • 131
4
votes
1 answer

Converting character in date/time format (POSIXct) works on Windows not Linux

I can't figure out why the following line of R script works perfectly fine on Windows (7, 64bit with R 3.0.2 64bit) but not on Linux (3.12.1-1-ARCH GNU/Linux 64bit with R 3.0.2 64bit): Windows: >strptime("2013-05-08 10:27:50", format="%Y-%m-%d…
4
votes
2 answers

Parsing a YYYY-MM-DD date strictly on Linux

POSIX defines a handy function, strptime, that can be used for parsing dates and times. Thus, theoretically, if I have a date of the format "YYYY-MM-DD", I should be able to use strptime to parse it like this: char myDate[] = "2012-01-01"; struct…
Matt Patenaude
  • 4,497
  • 1
  • 22
  • 21
3
votes
1 answer

Parsing string dates in ruby such as "28-May-10"

I tried parsing using Date.parse("28-May-10").to_s Returns 0010-5-28 (which is 2000 years off!) How can I get ruby to interpret the two digit year properly. There are plenty of string to date conversion tricks out there on google but most handle…
Tarang
  • 75,157
  • 39
  • 215
  • 276
3
votes
1 answer

Can I assume that strptime will always fill in missing values with 0?

I have the following Perl code: print Time::Piece->strptime("2023:01:01 00:00:00.000", "%Y:%m:%d %H:%M:%S")->strftime("%Y:%m:%d %H:%M:%S") . "\n"; print Time::Piece->strptime("2023:01:02 00:00:00", "%Y:%m:%d %H:%M:%S%z")->strftime("%Y:%m:%d…
pacoverflow
  • 3,726
  • 11
  • 41
  • 71
3
votes
2 answers

Subtract SQL DATETIME from datetime.now() in Python

I have a DATETIME field in SQL. Its content is: 2012-08-26 13:00:00 I want to know how much time has passed from that date until now. In Python 2.7, it's easy: import time,datetime start = datetime.datetime.strptime('2012-08-26 13:00:00', '%Y-%m-%d…
1qazxsw2
  • 2,589
  • 4
  • 20
  • 19