Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Fwd: changing the format of the current date


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Fwd: changing the format of the current date
Date   Thu, 23 May 2013 03:21:06 +0100

It's down to adding a little polish to a shiny ornament but the format

%td_CCYY-NN-DD

puts the hyphens in at the outset, making the -subinstr()- call unnecessary.

Nick
[email protected]


On 22 May 2013 22:57, Radwin, David <[email protected]> wrote:
> Melanie,
>
> You need a colon in the first line instead of an equals sign and -trim-
> in the second line to get rid of an unwanted leading space. Try this:
>
>
> . local date: display %td_CCYY_NN_DD date(c(current_date), "DMY")
>
> . local date_string = subinstr(trim("`date'"), " " , "-", .)
>
> . save "`date_string'_example", replace
>
>
> David
> --
> David Radwin
> Senior Research Associate
> Education Studies Division
> RTI International
> 2150 Shattuck Ave., Suite 800
> Berkeley, CA 94704
> Phone: 510-665-8274
>
> www.rti.org
>
> *Please note new contact information*
>
>
>> -----Original Message-----
>> From: [email protected] [mailto:owner-
>> [email protected]] On Behalf Of Melanie Leis
>> Sent: Wednesday, May 22, 2013 2:34 PM
>> To: statalist
>> Subject: Re: st: Fwd: changing the format of the current date
>>
>> Thanks Bill and Nick, this is very helpful.
>>
>> Nevertheless, the reason I'd like to change the format on
>> c(current_date) is to incorporate it into the name of a file.  What
>> I've been doing is:
>>
>>      local c_date= c(current_date)
>>      local date_string = subinstr("`c_date'", " " , "-", .)
>>      save "`date_string'_example", replace
>>
>> Which yields a file name 22-May-2013_example
>>
>> I'd like a file name that is more like 2013_05_22_example
>>
>> Incorporating your suggestion I get:
>>
>>      local date= %td_CCYY_NN_DD date(c(current_date), "DMY")
>>      local date_string = subinstr("`date'", " " , "-", .)
>>      save "`date_string'_example", replace
>>
>> But after the first local macro I get an error that says
>>
>>      %td_CCYY_NN_DD invalid name
>>
>> Any suggestions on how I could fix this?
>>
>> Thank you so much!
>>
>> Melanie
>>
>> On Wed, May 22, 2013 at 1:10 PM, William Gould, StataCorp LP
>> <[email protected]> wrote:
>> > Melanie Leis <[email protected]> wrote,
>> >
>> >> Is there a way to change the format of the automated date in
>> >> c(current_date)?
>> >>
>> >> The automatic format is 22 May 2013
>> >>
>> >> I would like to get something that looks like 2013 05 22
>> >
>> >
>> > There's already been one good answer.  Here's another,
>> >
>> >         . display %td_CCYY_NN_DD date(c(current_date), "DMY")
>> >         2013 05 22
>> >
>> >
>> > -- Bill
>> > [email protected]
>
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/statalist-faq/
> *   http://www.ats.ucla.edu/stat/stata/
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index