How to Get Current Date and Time in R

To get the current date in R, you can use the “Sys.Date()” function.

Sys.Date()

Output

[1] "2023-05-23"

To get the absolute date-time value in R, you can use the “Sys.time()” function.

Sys.time()

Output

[1] "2023-05-23 22:13:24 IST"

To get the system time in a fixed-format character string, you can use the “date()” function.

date()

Output

[1] "Thu Mar 11 16:59:16 2021"

Dates can be imported from character, numeric, POSIXlt, and POSIXct formats in R using as.Date() method.

That’s it.

Leave a Comment