Weekday
In this, we will look into the %a, %A, and %u specifiers which give the abbreviated weekday, full weekday, and numbered weekday starting from Monday.
Example:
R
# today date date<- Sys.Date () # abbreviated Day format (date,format= "%a" ) # full Day format (date,format= "%A" ) # weekday format (date,format= "%u" ) |
Output
[1] "Sat"
[1] "Saturday"
[1] "6"
How to Use Date Formats in R
In this article, we will be looking at the approaches to using the date formats in the R programming language,
R programming language provides several functions that deal with date and time. These functions are used to format and convert the date from one form to another form. R provides a format function that accepts the date objects and also a format parameter that allows us to specify the format of the date we needed. R provides various format specifiers which are mentioned below in Table-
Specifier |
Description |
---|---|
%a |
Abbreviated weekday |
%A |
Full weekday |
%b |
Abbreviated month |
%B |
Full month |
%C |
Century |
%y |
Year without century |
%Y |
Year with century |
%d |
Day of month (01-31) |
%j |
Day in Year (001-366) |
%m |
Month of year (01-12) |
%D |
Data in %m/%d/%y format |
%u |
Weekday (01-07) Starts on Monday |
Note:To get the Today date, R provides a method called sys.Date() which returns the today date.