1

I have a column "datetime" which have value as "899-12-30 07:00:00"

on checking the information I am getting.

> typeof(time_info$datetime)
[1] "double"
> class(time_info$datetime)
[1] "POSIXct" "POSIXt"

I want to extract just the time which is 0700 without seconds in this case. How can I do this ?

Frank
  • 66,179
  • 8
  • 96
  • 180
Archit gupta
  • 147
  • 1
  • 2
  • 11
  • answer is here:http://stackoverflow.com/questions/39756615/remove-seconds-from-time-in-r – Adamm May 12 '17 at 09:34

3 Answers3

3

We can do this using format

format(strptime(str1, "%Y-%m-%d %H:%M:%S"), "%H%M")

data

str1 <- "899-12-30 07:00:00"
akrun
  • 874,273
  • 37
  • 540
  • 662
-1

Let's say we have Time.now ( youhave your own time) that is the way

t = Time.now
t.strftime("%I:%M%p")
Sergio Suarez
  • 117
  • 1
  • 1
  • 10
-2

Or you can directly extract time part:

substr("899-12-30 07:00:00",11,15)
# [1] "07:00"
Erdem Akkas
  • 2,062
  • 10
  • 15