you can remove the leading zeros wirh the following regular expression;

 gsub("(^0|(/)0)", "\\2", format(asd, format = '%d/%m/%Y'))
[1] "3/1/2012"


On Wed, Dec 26, 2012 at 2:25 PM, Ron Michael <ron_michae...@yahoo.com> wrote:
> Thanks Jim for your reply.
>
> However I want "3/1/2012" not "03/01/2012"
>
> Any idea ?
>
> Thanks
>
>
> ----- Original Message -----
> From: jim holtman <jholt...@gmail.com>
> To: Ron Michael <ron_michae...@yahoo.com>
> Cc: "r-help@r-project.org" <r-help@r-project.org>
> Sent: Thursday, 27 December 2012 1:01 AM
> Subject: Re: [R] Working with date
>
> forgot you were asking for mdy format
>
>> # interchange day and month
>> format(asd, format = '%d/%m/%Y')
> [1] "03/01/2012"
>>
>
>
> On Wed, Dec 26, 2012 at 2:14 PM, jim holtman <jholt...@gmail.com> wrote:
>> try this:
>>
>>> asd <- as.Date("2012-01-03")
>>> asd
>> [1] "2012-01-03"
>>> format(asd, format = '%m/%d/%Y')
>> [1] "01/03/2012"
>>>
>>
>>
>>
>> On Wed, Dec 26, 2012 at 1:31 PM, Ron Michael <ron_michae...@yahoo.com> wrote:
>>> asd <- as.Date("2012-01-03")
>>
>>
>>
>> --
>> Jim Holtman
>> Data Munger Guru
>>
>> What is the problem that you are trying to solve?
>> Tell me what you want to do, not how you want to do it.
>
>
>
> --
> Jim Holtman
> Data Munger Guru
>
> What is the problem that you are trying to solve?
> Tell me what you want to do, not how you want to do it.
>



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.

______________________________________________
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