Parsing date strings

Parsing date strings

No votes yet

# Another version using location and substrings:

x <- as.POSIXct("2005-09-01 01:25:46.9")
print(x) #note R didn't round up seconds, and added timezone

yr <- substring(x,1,4)
m <- substring(x,6,7)
d <- substring(x,9,10)
hour <- substring(x,12,13)
min <- substring(x,15,16)
sec <- substring(x,18,19) #note, I decided to truncate decimals,
#you don't have to

## This is simple and you only have to print a variable first, to see
## how it is arranged.

Syndicate content