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
14
votes
2 answers

AM/PM string is not properly recognized by strptime

I have encountered something unexpected while working with the function strptime(). The format of the date I have consists of "1/22/2013 11:00:00 P.M" . The format I am using for this is "%m/%d/%Y %I:%M:%S %p". The code is as…
pmehrotra
  • 143
  • 1
  • 1
  • 4
13
votes
2 answers

Parse timestamp with a.m./p.m

I have a file that formats time stamps like 25/03/2011 9:15:00 p.m. How can I parse this text to a Date-Time class with either strptime or as.POSIXct? Here is what almost works: > as.POSIXct("25/03/2011 9:15:00", format="%d/%m/%Y %I:%M:%S",…
Mike T
  • 41,085
  • 18
  • 152
  • 203
13
votes
1 answer

Module 'datetime' has no attribute 'strptime'

I am totally new into programming, and I am giving a stab to python reading CSV files with Pythin. I am doing this using Spyder. I am getting a the error "module 'datetime' has no attribute 'strptime'", and can't figure it out. Any help will be…
Galvarado
  • 141
  • 1
  • 5
13
votes
5 answers

How to parse datetime that ends with `Z`?

I have the following datetime string s: 2017-10-18T04:46:53.553472514Z I parese it like that: t = datetime.strptime(s, '%Y-%m-%dT%H:%M:%SZ') how to fix ValueError: time data '2017-10-18T04:46:53.553472514Z' does not match format…
user6611764
13
votes
1 answer

Why c++ standard support function strftime but not strptime?

Why C++ standard support function strftime() but not strptime()? strftime() is available to change a time to string, but there isn't a function which can change a string back to time. On Posix strptime() is available as a C-like function, using it…
songyuanyao
  • 169,198
  • 16
  • 310
  • 405
13
votes
2 answers

Compiler gets warnings when using strptime function (C)

Typing man strptime it sais that this function needs to have declared _XOPEN_SOURCE and included time.h header. I did it. But, when I try to compile my code I get: ./check.c:56: warning: implicit declaration of function ‘strptime’ Look at my…
artaxerxe
  • 6,281
  • 21
  • 68
  • 106
13
votes
3 answers

Parsing date and timestamps in Python with time.strptime format

My cloud server logs time in this format: [17/Dec/2011:09:48:49 -0600] To read it into Python variables, I can say: >>>str = '17/Dec/2011:09:48:49 -0600' >>>import time >>>print time.strptime(str,"%d/%b/%Y:%H:%M:%S…
TGanoe
  • 349
  • 1
  • 3
  • 10
12
votes
2 answers

How to extract only the month and day from a datetime object?

I was trying to do a scatterplot, and my x-axis needs to be each individual day in a year. I first read in the datafile and get the date column, which are filled with integers like, 19800801. So I convert this integer to datetime by…
Candice Zhang
  • 211
  • 1
  • 3
  • 10
12
votes
1 answer

Applying strptime function to pandas series

I have a pandas DataSeries that contains a string formatted date in the form of: 2016-01-14 11:39:54 I would like to convert the string to a timestamp. I am using the apply method to attemp to pass 'datetime.strptime' to each element of the…
thron of three
  • 521
  • 2
  • 6
  • 19
12
votes
2 answers

dplyr does not group data by date

I am trying to calculate the frequency of bikes that are taken by people using a dataset provided by Leada. Here is the code: library(dplyr) setAs("character", "POSIXlt", function(from) strptime(from, format = "%m/%d/%y %H:%M")) d <-…
Sergei
  • 1,617
  • 15
  • 31
12
votes
2 answers

Sortable, readable and standard time format for logs

Timestamp format in logs Most log lines contain a timestamp and event description: [When] [What] e.g.: [23/Jul/2013:19:35:11 +0000] Processing started. [23/Jul/2013:19:36:11 +0000] Processed 1000 items. [23/Jul/2013:19:37:11 +0000] Processing…
Adam Matan
  • 128,757
  • 147
  • 397
  • 562
10
votes
4 answers

Converting time format to numeric with R

In most cases, we convert numeric time to POSIXct format using R. However, if we want to compare two time points, then we would prefer the numeric time format. For example, I have a date format like "2001-03-13 10:31:00", begin <- "2001-03-13…
Frank Wang
  • 1,462
  • 3
  • 17
  • 39
10
votes
3 answers

Why does python's datetime.datetime.strptime('201412', '%Y%m%d') not raise a ValueError?

In the format I am given, the date 2014-01-02 would be represented by "20140102". This is correctly parsed with the standard strptime: >>> datetime.datetime.strptime("20140102", "%Y%m%d") datetime.datetime(2014, 1, 2, 0, 0) In this format,…
user2957943
  • 173
  • 2
  • 8
10
votes
1 answer

How to properly check strptime for valid dates in C

I'm doing the following to convert and check a date, however, I'm not sure why the following date keeps validating as true. Wouldn't %d check only for [01,31] + leading zeros? Is there a better and more accurate way of doing this? #include…
user1024718
  • 573
  • 6
  • 18
9
votes
2 answers

Formatting date times provided as strings in Django

In my Django application I get times from a webservice, provided as a string, that I use in my templates: {{date.string}} This provides me with a date such as: 2009-06-11 17:02:09+0000 These are obviously a bit ugly, and I'd like to present them…
Tristan Brotherton
  • 2,533
  • 7
  • 32
  • 38
1 2
3
51 52