How can I keep a date formatted in R using sqldf?
Asked Answered
S

1

8

How do I rename a date field in SQLDF without changing the format?

See my example below where my renamed date field "dt" converts the date to a number. How do I avoid this, or convert it back to a date?

#Question for Stack Exchange
df <- data.frame (date = c("2014-12-01","2014-12-02","2014-12-03"),
            acct = c(1,2,3))

df$date = as.Date(df$date)

library("sqldf")
sqldf('
    select 
        date as dt,
        date,
        acct
    from df ')


     dt       date acct
1 16405 2014-12-01    1
2 16406 2014-12-02    2
3 16407 2014-12-03    3
Subjacent answered 30/12, 2014 at 17:36 Comment(0)
W
12

Specify the method as follows:

sqldf('select date as dt__Date,
              date as date__Date,
              acct
       from df',
      method = "name__class")
Winnah answered 30/12, 2014 at 17:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.