Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert sqlite dates to a date in R

I am working with a sqlite database table. I have pulled the data into R using the RSQLite package. One of the columns holds a date. Sqlite is storing it as a Real number, the number of days since noon in Greenwich on November 24, 4714 B.C. (e.g.1264896000). Any ideas on how to convert this to a valid date in R? I tried the following

as.POSIXct(1264896000,origin = "-4714-11-24")

However, this doesn't work as the character string in not in a standard form. Any ideas?

like image 225
iantist Avatar asked Nov 04 '25 12:11

iantist


1 Answers

I tested my theory that your claim about the origin was unlikely. The theory that these are POSIX date-times (origin= 1970-01-01 and times in seconds) seems supported by experiment.

> as.POSIXct(1264896000,origin = "1970-01-01")
[1] "2010-01-30 16:00:00 PST"
like image 143
IRTFM Avatar answered Nov 06 '25 01:11

IRTFM