R Func As Date
# R as.Date() Function - Date Conversion
[ R Language Examples](https://example.com/r/r-examples.html)
The R as.Date() function is used to convert character data to date type.
The date type is the foundation for handling time series data in R, supporting addition/subtraction operations and comparisons.
The as.Date() function syntax is as follows:
as.Date(x, format = "%Y-%m-%d")
**Parameter Description:**
* **x** Character date string.
* **format** Date format string.
| Format Specifier | Meaning | Example |
| --- | --- | --- |
| %Y | Four-digit year | 2026 |
| %y | Two-digit year | 26 |
| %m | Month (01-12) | 05 |
| %d | Day (01-31) | 11 |
| %B | Full month name | May |
## Examples
# Standard format conversion
date1 <-as.Date("2026-05-11")
print(date1)
print(paste("Type:", class(date1)))
# Non-standard format
date2 <-as.Date("11/05/2026", format="%d/%m/%Y")
print(date2)
date3 <-as.Date("May 11, 2026", format="%B %d, %Y")
print(date3)
# Date operations
today <-as.Date("2026-05-11")
future <- today +30
print(paste("After 30 days:", future))
print(paste("Days difference:", as.numeric(future - today)))
Executing the above code outputs:
"2026-05-11" "Type: Date" "2026-05-11" "2026-05-11" "After 30 days: 2026-06-10" "Days difference: 30"
YouTip