I've been trying to understand the as.Date functionality and I have a date
and time stamp field that looks like this:

"Tue Sep 15 09:22:09 -0600 2009"

and I need to turn it into an R Date object for analysis.

Simple date conversions I have down, no problem:

> adate = c("7/30/1959")
> as.Date(adate,"%m/%d/%Y")
[1] "1959-07-30"
> 

But when it comes to the type of date/time string format I have above, I
can't figure out a format string that will work.

The timezone offset is one part that causes problems.  Building up to a
working format string for the full time stamp string, I can make it as far
as:

> adate = c("Tue Sep 15 09:22:09 -0600 2009")
> as.Date(adate,format="%a %b %d %H:%M:%S")
[1] "2009-09-15"

(apparently year defaults to current year when it's not specified in the
format string).  Because the Year comes after the timezone offset, I have to
deal with the timezone offset in the format string. 

But when I get to the timezone offset value I can't use "%z" or "%Z" because
those are "output only"

> as.Date(adate,format="%a %b %d %H:%M:%S %z %Y")
[1] NA

I'm close, but can't incorporate the timezone offset field in the date/time
stamp string.

What am I missing?   I suppose one workaround is to split the date/time
string into its component parts, reassemble it into a string as.Date can
deal with, but that seems to defeat one of the purposes of as.Date's format
capability.

Any advice for how to translate a "Tue Sep 15 09:22:09 -0600 2009" into an R
Date object?

Landon

-- 
View this message in context: 
http://www.nabble.com/Simple-as.Date-question-dealing-with-a-timezone-offset-tp25491955p25491955.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help@r-project.org 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 via email to