Re: [R] Strptime

From: Dirk Eddelbuettel <edd_at_debian.org>
Date: Fri, 30 May 2008 12:09:15 +0000

On Fri, May 30, 2008 at 12:58:27PM +0100, Creighton, Sean wrote:
> Hi
>
> This code should explain what I'm trying to do
>
> > strptime("30-Jan-08", "%d-%b-%y")
> [1] "2008-01-30"
> >
> > format(strptime("30-Jan-08", "%d-%b-%y") , "%b-%y")
> [1] "Jan-08"
> >
> > strptime(format(strptime("30-Jan-08", "%d-%b-%y") , "%b-%y") ,
> "%b-%y")
> [1] NA
>
>
> I have a string of the form "Jan-08" but I can't seem to get strptime to
> recognise it. The format function can take the date object and using the
> given flags "%b-%y" create a string. It can't, however, seem to go back
> the other way, i.e. as in the line below:
>
> > strptime(format(strptime("30-Jan-08", "%d-%b-%y") , "%d-%m-%Y"),
> "%d-%m-%Y")
> [1] "2008-01-30"
>
> Any tips?

Supply (a|any) date to make it a complete date to parse:

> strptime(paste("30", format(strptime("30-Jan-08", "%d-%b-%y") , "%b-%y"), sep="-"), "%d-%b-%y")
[1] "2008-01-30"

Dirk

-- 
Three out of two people have difficulties with fractions.

______________________________________________
R-help_at_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.
Received on Mon 02 Jun 2008 - 04:34:07 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 02 Jun 2008 - 05:30:35 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive