R Cheatsheet: Dates and Times
#R stores a date as the number of days counted from «Zero Day» which is January the first 1970. The same principle used by SAS, but the latter uses another «Start Date» or «Zero Day»
#Dates are represented as a «Date Class»
#On the other hand, times (number of seconds from «Start Date») are represented by any of the following classes:
#POSIXct (a single integer value representing the time)
#POSIXlt (a list of values representing the time)
#Defining a Date:
bday<-as.date(«1990-01-25»)
#If we need to see the «value» of a particular date class we have to unclass it:
#So, it means it have passed 7329 since January 25th, 1990, the date stored in bday. Unclass is equivalent to the datepart() function of SAS.
#To obtain the current datetime, equals to TODAY() in SAS
dt<-Sys.time
#Of course we can use the POSIXlt to de-construct and obtain a singular value of our date.
#strptime is a useful function you can use to convert time in a POSIXlt or POSIXct format.