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"

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"

Related Articles & Further Resources

Please find some related R programming tutorials in the following list:

Leave a Reply

Your email address will not be published.

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Menu
Top