vanao veneri
vanao veneri

Reputation: 1054

Converting rather long time string

I have a bunch of string values that represent date and time and I need to do some math with it (like finding out what's later). I am stuck with the strptime function. This is what I have. Maybe you guys can help me out a bit.

tst1 <- "2013-01-28T11:01:54.385+0430"

#this results in NA: 
y <- strptime(tst1, format="%c")
y <- strptime(tst1, format="%y-%m-%d")
y <- strptime(tst1, format="%y-%m-%dT%H:%M:%OS%z")

#and this messes the time up: 
y <- strftime(tst1, format="%c")
y <- strftime(tst1, format="%y-%m-%d")
y <- strftime(tst1, format="%y-%m-%dT%H:%M:%OS%z")

Upvotes: 0

Views: 28

Answers (1)

MrFlick
MrFlick

Reputation: 206486

You should be using

strptime("2013-01-28T11:01:54.385+0430", format="%Y-%m-%dT%H:%M:%OS%z")

Note the %Y because you have a four digit year. Also note that strptime is for parsing strings as dates and strftime is for formatting dates as strings.

Upvotes: 2

Related Questions