strptime

PHP strptime format bug?

I am wrestling with a php 5.2.6 problem. An api we use returns dates in this format DDMMYYYYHHMM. Exactly that format, fixed length, no delimiters. However, in my experimentation, this format seems to break strptime, which returns a false (fail) when I feed it a date in this format. It can reproduced, at least on my system, with this exa...

strptime in Javascript

I have a date input field that allows the user to enter in a date and I need to validate this input (I already have server side validation), but the trick is that the format is locale dependent. I already have a system for translating the strptime format string to the the user's preference and I would like to use this same format for val...

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 in a nice format to my users. Django has a great built in date formatter, which would do ...

python datetime strptime wildcard

I want to parse dates like these into a datetime object: December 12th, 2008 January 1st, 2009 The following will work for the first date: datetime.strptime("December 12th, 2008", "%B %dth, %Y") but will fail for the second because of the suffix to the day number ('st'). So, is there an undocumented wildcard character in strptime...

converting strptime into 'X hours ago'

I have a a date in strptime that I want to show as 'X hours ago'. I can happily convert hours into days and weeks etc. but I don't know how to do the initial sum. Here is how I'm converting the string into strptime: time.strptime(obj.created_at, '%a %b %d %H:%M:%S +0000 %Y') p.s. bonus points for figuring out why it won't take %z for ...

How can I account for "AM" or "PM" with datetime.strptime?

Specifically I have code that simplifies to this: from datetime import datetime date_string = '2009-11-29 03:17 PM' format = '%Y-%m-%d %H:%M %p' my_date = datetime.strptime(date_string, format) # This prints '2009-11-29 03:17 AM' print my_date.strftime(format) What gives? Does Python just ignore the period specifier when parsing date...

[r] How to parse milliseconds in R?

How do I use strptime or any other functions to parse timestamps with milliseconds in R? > time[1] [1] "2010-01-15 13:55:23.975" > strptime(time[1], format="%Y-%m-%d %H:%M:%S.%f") [1] NA > strptime(time[1], format="%Y-%m-%d %H:%M:%S") [1] "2010-01-15 13:55:23"` ...

Coverting a string to a formatted date-time string using Python

I'm trying to convert a string "20091229050936" into "05:09 29 December 2009 (UTC)" >>>import time >>>s = time.strptime("20091229050936", "%Y%m%d%H%M%S") >>>print s.strftime('%H:%M %d %B %Y (UTC)') gives AttributeError: 'time.struct_time' object has no attribute 'strftime' clearly, I've made a mistake: time is wrong, it's a datetime ...

datetime.datetime.strptime problem

My input string is '16-MAR-2010 03:37:04' and i want to store it as datetime. I am trying to use: db_inst.HB_Create_Ship_Date = datetime.strptime(fields[7]," %d-%b-%Y %H:%M:%S ") fields[7] = '16-MAR-2010 03:37:04' I am getting an error: ::ValueError: time data '16-MAR-2010 03:37:04' does not match format ' %d-%b-%Y %H:%M:%S ' ...

Python 2.5 fails on a datetime.strptime format

I have seen several questions with people asking about the same problem but none of the answers are helping me. I'm receiving this error: pydev debugger: starting Traceback (most recent call last): >>> File "/usr/local/zend/apache2/htdocs/pyth/src/conn.py", line 23, in <module> userConnDate = datetime.strptime(data[1] + ' ' +...

2 digit years using strptime() is not able to parse birthdays very well.

Consider the following birthdays (as dob): 1-Jun-68 1-Jun-69 When parsed with Python’s datetime.strptime(dob, '%d-%b-%y') will yield: datetime.datetime(2068, 6, 1, 0, 0) datetime.datetime(1969, 6, 1, 0, 0) Well of course they’re supposed to be born in the same decade but now it’s not even in the same century! According to the do...

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", &t); std::cout<<t.tm_hour<<endl; strptime("Wed 4/18/2007 4:28:22 AM", "%a %m/%d/%Y %H:%M:%S %p", &t); ...

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 figure out what kind of timeformat this is. By the way, I'm a newbie at the Python langu...

unknown timezone name in R strptime/as.POSIXct

Where can I find a list of all legal time names for R function as.POSIXct? 'as.POSIXct("1970-01-01",tz="CST")' will generate warning that "CST" (Central Standard Time) is unknown. Thanks ...