Convert H:MM:SS PM /AM into 24 HR syntax

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Convert H:MM:SS PM /AM into 24 HR syntax

JustADude
I've got an array of times in H:MM:SS PM/AM format, e.g. "5:27:15 PM" (no leading zero), and I would like to convert them over to 24 HR syntax, e.g. HH:MM:SS.

If it matters, the times are from the Central Time zone.

Is there a command to convert the time to a 24HR format?

I tried the following:
ptime("5:27:15 PM", "%H:%M:%S")
[1] "2009-11-04 05:27:15"
> strptime("5:27:15 PM", "%h:%M:%S")
[1] NA
> strptime("5:27:15 PM", "%R:%M:%S")
[1] NA
> strptime("5:27:15 PM", "%r:%M:%S")
[1] NA
Note that the top one is incorrect due to it not using the "PM" indicator.

Thank you for any insights any feedback that can be provided.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Convert H:MM:SS PM /AM into 24 HR syntax

Henrique Dallazuanna
Try this:

strptime("5:27:15 PM", "%I:%M:%S %p")

On Wed, Nov 4, 2009 at 3:19 PM, Jason Rupert <[hidden email]> wrote:

> I've got an array of times in H:MM:SS PM/AM format, e.g. "5:27:15 PM" (no leading zero), and I would like to convert them over to 24 HR syntax, e.g. HH:MM:SS.
>
> If it matters, the times are from the Central Time zone.
>
> Is there a command to convert the time to a 24HR format?
>
> I tried the following:
> ptime("5:27:15 PM", "%H:%M:%S")
> [1] "2009-11-04 05:27:15"
>> strptime("5:27:15 PM", "%h:%M:%S")
> [1] NA
>> strptime("5:27:15 PM", "%R:%M:%S")
> [1] NA
>> strptime("5:27:15 PM", "%r:%M:%S")
> [1] NA
> Note that the top one is incorrect due to it not using the "PM" indicator.
>
> Thank you for any insights any feedback that can be provided.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



--
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Convert H:MM:SS PM /AM into 24 HR syntax

JustADude
This is exactly what I needed.  Thanks again for all your help.



----- Original Message ----
From: Henrique Dallazuanna <[hidden email]>
To: Jason Rupert <[hidden email]>
Cc: [hidden email]
Sent: Wed, November 4, 2009 11:22:52 AM
Subject: Re: [R] Convert H:MM:SS PM /AM into 24 HR syntax

Try this:

strptime("5:27:15 PM", "%I:%M:%S %p")

On Wed, Nov 4, 2009 at 3:19 PM, Jason Rupert <[hidden email]> wrote:

> I've got an array of times in H:MM:SS PM/AM format, e.g. "5:27:15 PM" (no leading zero), and I would like to convert them over to 24 HR syntax, e.g. HH:MM:SS.
>
> If it matters, the times are from the Central Time zone.
>
> Is there a command to convert the time to a 24HR format?
>
> I tried the following:
> ptime("5:27:15 PM", "%H:%M:%S")
> [1] "2009-11-04 05:27:15"
>> strptime("5:27:15 PM", "%h:%M:%S")
> [1] NA
>> strptime("5:27:15 PM", "%R:%M:%S")
> [1] NA
>> strptime("5:27:15 PM", "%r:%M:%S")
> [1] NA
> Note that the top one is incorrect due to it not using the "PM" indicator.
>
> Thank you for any insights any feedback that can be provided.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



--
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O





______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.