Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Striping the time out out a date and time vector

I wish to strip the time (hours and minuets) from the following vector but the time seems to defult to 00:00 when I use the following approach.

mytime = "2023-08-27 21:06:00Z"
format(strptime(mytime, "%F"), "%H:%M")

This returns 00:00 but here I want it to return 21:06, i’ve also tried wrapping as.POSIXct() around gtime but had the same results

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

%F is Equivalent to %Y-%m-%d. So add %H:%M:%S or %T to get also the time.

format(strptime(mytime, "%F %H:%M:%S"), "%H:%M")
#[1] "21:06"

format(strptime(mytime, "%F %T"), "%H:%M")
#[1] "21:06"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading