How to parse milliseconds?

Courtesy of the ?strptime help file (with the example changed to your value): > z <- strptime(“2010-01-15 13:55:23.975”, “%Y-%m-%d %H:%M:%OS”) > z # prints without fractional seconds [1] “2010-01-15 13:55:23 UTC” > op <- options(digits.secs=3) > z [1] “2010-01-15 13:55:23.975 UTC” > options(op) #reset options

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

tech