Remove AM & PM from Date & Time in R (Example Code)

This article illustrates how to drop AM and PM from a date and time object in R programming.

Example Data

x <- "2025-05-10 10:17:52 PM"                        # Constructing an example date & time
x
# [1] "2025-05-10 10:17:52 PM"

Example: Drop AM & PM from Dates & Times Using parse_date_time() Function of lubridate Package

install.packages("lubridate")                        # Install & load lubridate
library("lubridate")
x_upd <- parse_date_time(x, "%y-%m-%d %I:%M:%S %p")  # Removing AM & PM
x_upd
# [1] "2025-05-10 22:17:52 UTC"

Related Articles & Further Resources

Have a look at the following tutorials. They illustrate topics such as character strings, coding errors, data conversion, and extracting data:

Leave a Reply

Your email address will not be published. Required fields are marked *

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