I am confronted with a weird phenomenom when extracting data out of a SQLite 3 database using the RSQLite 1.0.0 package. All except the year of the datetime value gets truncated!
See an example:
Following I am extracting a DATETIME column:
library(RSQLite)
src_path <- "../DataLocked/Study.db"
con <- dbConnect(SQLite(), src_path)
dbGetQuery(con, "SELECT Todesdatum FROM Kontraindikation LIMIT 10")
This gets me the following result:
Todesdatum
1 NA
2 NA
3 2004
4 NA
5 2006
6 NA
7 NA
8 NA
9 NA
10 NA
Now from the same table I am omitting NON NULL values:
dbGetQuery(con, "SELECT Todesdatum FROM Kontraindikation WHERE Todesdatum NOTNULL")
This gets me the following result:
Todesdatum
1 2004-09-16 00:00:00
2 2006-04-20 00:00:00
3 2006-06-02 00:00:00
4 2007-09-15 00:00:00
5 2008-06-12 00:00:00
6 2005-10-04 00:00:00
7 2008-11-22 00:00:00
8 2005-12-22 00:00:00
9 2006-11-05 00:00:00
10 2006-02-08 00:00:00
...
Now I try to do a string format on the DATETIME field:
dbGetQuery(con, "SELECT strftime('%Y-%m-%d',Todesdatum) as fixed_Todesdatum FROM Kontraindikation 10")
That works:
fixed_Todesdatum
1 <NA>
2 <NA>
3 2004-09-16
4 <NA>
5 2006-04-20
6 <NA>
7 <NA>
8 <NA>
9 <NA>
10 <NA>
I have really no idea what is going on and how to solve this. I would be very thankful for any pointers.
Greetings, Alex