HI Farnoosh, Try: D1= c("5/25/2012 14:48", "5/29/2012 16:53", "6/1/2012 18:30") D2= c("6/8/2012 21:26", "6/11/2012 15:10" , "6/14/2012 17:57") as.numeric(as.POSIXct(D2,format="%m/%d/%Y %H:%M")-as.POSIXct(D1,format="%m/%d/%Y %H:%M")) #days #[1] 14.27639 12.92847 12.97708
#or as.numeric(difftime(as.POSIXct(D2,format="%m/%d/%Y %H:%M"),as.POSIXct(D1,format="%m/%d/%Y %H:%M"),units="days")) #[1] 14.27639 12.92847 12.97708 A.K. On Friday, February 28, 2014 5:27 PM, farnoosh sheikhi <farnoosh...@yahoo.com> wrote: Hi, I have a two column with date/time format like below: D1= ( 5/25/2012 14:48, 5/29/2012 16:53, 6/1/2012 18:30). D2= (6/8/2012 21:26, 6/11/2012 15:10 , 6/14/2012 17:57) I want to subtract D1-D2 and obtain the difference between them. I have tried as.date and as.numeric, but the values convert to NAs. Thanks for your help. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.