[R] Working with date

Jeff Newmiller jdnewmil at dcn.davis.CA.us
Wed Dec 26 20:19:20 CET 2012


If you don't have to be finicky about leading zeros, the easy way is:

as.character(asd,format="%d/%m/%Y")

?strptime

If you are going to be finicky, then

asdlt <- as.POSIXlt(asd)
with(asdlt,sprintf("%d/%d/%d",mday,mon+1,year+1900))

?as.POSIXlt
?sprintf
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.

Ron Michael <ron_michael70 at yahoo.com> wrote:

>Hi,
>
>Let say I have a date variable:
>
>>  asd <- as.Date("2012-01-03")
>> asd
>[1] "2012-01-03"
>
>
>
>Now, I want to express this date like 3/1/2012.
>
>can somebody help me how to achieve that?
>
>Thanks,
>
>______________________________________________
>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.




More information about the R-help mailing list