To format Dates
we use the format(date, format="%Y-%m-%d")
function with either the POSIXct
(given from as.POSIXct()
) or POSIXlt
(given from as.POSIXlt()
)
d = as.Date("2016-07-21") # Current Date Time Stamp format(d,"%a") # Abbreviated Weekday ## [1] "Thu" format(d,"%A") # Full Weekday ## [1] "Thursday" format(d,"%b") # Abbreviated Month ## [1] "Jul" format(d,"%B") # Full Month ## [1] "July" format(d,"%m") # 00-12 Month Format ## [1] "07" format(d,"%d") # 00-31 Day Format ## [1] "21" format(d,"%e") # 0-31 Day Format ## [1] "21" format(d,"%y") # 00-99 Year ## [1] "16" format(d,"%Y") # Year with Century ## [1] "2016"
For more, see ?strptime
.