How to convert integer into date object python?

This question is already answered, but for the benefit of others looking at this question I’d like to add the following suggestion: Instead of doing the slicing yourself as suggested in the accepted answer, you might also use strptime() which is (IMHO) easier to read and perhaps the preferred way to do this conversion. import … Read more

Parsing datetime strings containing nanoseconds

You can see from the source that datetime objects don’t support anything more fine than microseconds. As pointed out by Mike Pennington in the comments, this is likely because computer hardware clocks aren’t nearly that precise. Wikipedia says that HPET has frequency “at least 10 MHz,” which means one tick per 100 nanoseconds. If you … Read more

Changing date format in R

There are two steps here: Parse the data. Your example is not fully reproducible, is the data in a file, or the variable in a text or factor variable? Let us assume the latter, then if you data.frame is called X, you can do X$newdate <- strptime(as.character(X$date), “%d/%m/%Y”) Now the newdate column should be of … Read more

What are the “standard unambiguous date” formats for string-to-date conversion in R?

This is documented behavior. From ?as.Date: format: A character string. If not specified, it will try ‘”%Y-%m-%d”‘ then ‘”%Y/%m/%d”‘ on the first non-‘NA’ element, and give an error if neither works. as.Date(“01 Jan 2000”) yields an error because the format isn’t one of the two listed above. as.Date(“01/01/2000”) yields an incorrect answer because the date … Read more

Get date from week number

A week number is not enough to generate a date; you need a day of the week as well. Add a default: import datetime d = “2013-W26” r = datetime.datetime.strptime(d + ‘-1’, “%Y-W%W-%w”) print(r) The -1 and -%w pattern tells the parser to pick the Monday in that week. This outputs: 2013-07-01 00:00:00 %W uses … Read more

strptime, as.POSIXct and as.Date return unexpected NA

I think it is exactly as you guessed, strptime fails to parse your date-time string because of your locales. Your string contains both abbreviated weekday (%a) and abbreviated month name (%b). These time specifications are described in ?strptime: Details %a: Abbreviated weekday name in the current locale on this platform %b: Abbreviated month name in … Read more