• convert text into date:
    > newvariable<-as.Date("2015-01-28", "%Y-%m-%d") 
    > newvariable
    [1] "2015-01-28"
    
  • convert text into date/time:
    > newvariable<-strptime("2015-01-28 17:45:23", "%Y-%m-%d %H:%M:%S") 
    > newvariable
    [1] "2015-01-28 17:45:23 CET"
    
  • convert text into date/time:
    > mytime1<-strptime("2015-01-28 17:45:23", "%Y-%m-%d %H:%M:%S")
    > mytime2<-strptime("2015-01-30 19:00:00", "%Y-%m-%d %H:%M:%S")
    > mytime1
    [1] "2015-01-28 17:45:23 CET"
    > mytime2
    [1] "2015-01-30 19:00:00 CET"
    > difftime(mytime1, mytime2, units="hours")
    Time difference of -49.24361 hours
    > difftime(mytime2, mytime1, units="hours")
    Time difference of 49.24361 hours
    > difftime(mytime2, mytime1, units="days")
    Time difference of 2.051817 days