Change Year/Month/Day/Hour/Minute/Second to Date/Time in R (Example Code)
In this article you’ll learn how to change a character string to a date-time object with hours, minutes, and seconds in the R programming language.
Creation of Example Data
x <- "26-04-2024 06:28:51" # Example date as character string x # [1] "26-04-2024 06:28:51" |
x <- "26-04-2024 06:28:51" # Example date as character string x # [1] "26-04-2024 06:28:51"
Example: Applying as.POSIXlt() Function to Convert Character String to Date-Time Object
as.POSIXlt(x, format = "%d-%m-%Y %H:%M:%S") # Applying as.POSIXlt() # [1] "2024-04-26 06:28:51 UTC" |
as.POSIXlt(x, format = "%d-%m-%Y %H:%M:%S") # Applying as.POSIXlt() # [1] "2024-04-26 06:28:51 UTC"
Related Articles & Further Resources
Please find some related R programming tutorials in the following list: