[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: minor annoyance

From   Nick Winter <[email protected]>
To   [email protected]
Subject   Re: st: minor annoyance
Date   Thu, 07 Aug 2008 14:28:53 -0400

If you are doing this, even better would be to include the following in

global today date("\`c(current_date)'","DMY")

Note the backslash before the open-single-quote (`), which means the global macro contains the literal string `c(current_date)' which is evaluated every time the global is called, rather than containing the value of c(current_date) at the time you assign the global.

Then $today will give you the date number, and it will work even if you've been running Stata since yesterday.

You can see what's "really" in $today with -macro list-:

. mac list today
today: date("`c(current_date)'","DMY")

. di $today

. di %d $today

--Nick Winter

David Radwin wrote:


If you frequently need today's date formatted as a Stata date value or some other specific format like the one below, you might find it convenient to make a global macro like $today in your file.

The risk would be that if you leave your computer (and Stata) on overnight, the macro would refer to an earlier date.


At 8:58 AM -0400 8/7/08, Jeph Herrin wrote:

Even if one isn't using it to compare with a date
variable, one usually wants to reformat before using,
and converting to a date value is the easiest way
to proceed, eg,

local today=string(date("`c(current_date)'","DMY"),"%tdCCYY.NN.DD")

Nicholas Winter                                 434.924.6994 t
Assistant Professor                             434.924.3359 f
Department of Politics                  [email protected] e
University of Virginia w
PO Box 400787, 100 Cabell Hall
Charlottesville, VA 22904

*   For searches and help try:

© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index