Date: Tue, 11 Aug 2009 12:48:40 -0400
Reply-To: Daniel Robertson <email@example.com>
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: Daniel Robertson <firstname.lastname@example.org>
Subject: Re: Dynamic date writing
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Well, leave it to me to come up with a complicated solution when a
simple one will do!
Oliver, Richard wrote:
> compute datevar=$date11.
> will return the current date in the form dd-mmm-yyyy.
> If you don't like the dashes, add:
> datevar=replace(datevar, "-", "").
> -----Original Message-----
> From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU] On Behalf Of Daniel Robertson
> Sent: Tuesday, August 11, 2009 11:13 AM
> To: SPSSX-L@LISTSERV.UGA.EDU
> Subject: Re: Dynamic date writing
> There are probably clever non-Python ways to do this, but if you're
> using Python, getting the current local date is pretty easy using the
> datetime library:
> import datetime
> mydate = str(datetime.date.today())
> which returns '2009-08-11' as a string. If you want the date to be
> formatted differently, as in your example, you can extract and rearrange
> the date components, e.g., something like...
> myyear = str(datetime.date.today().year) # extract the year from the
> date object, as a string
> mymonth = str(datetime.date.today().month) # extract the month from
> the date object, as a string
> myday = str(datetime.date.today().day) # extract the day from the date
> object, as a string
> datestring = myyear[2:4] + mymonth.zfill(2) + myday # retain just the
> last two digits of the year, and if the month is a single digit, left
> pad it with a '0'
> ...which gives datestring a value of '090811'. I'm sure there are more
> elegant ways to do this in Python, but you get the idea.
> Mario Giesel wrote:
>> Hello, SPSS users, I've got a question on dynamic date writing:
>> I have daily exports of an increasing spss data file.
>> File names differ in the date they were written, e.g.
>> I want to insert the date part of the file name automatically,
>> i.e. the actual date is to be detected by the system and inserted into
>> the concatenated path. So far I use this solution:
>> DEFINE !path ()
>> DEFINE !date ()
>> SAVE OUTFILE = !path + !date + "_export.sav".
>> Here I have to change the date part manually, however.
>> Any suggestions are really welcome.
>> Good luck,
Senior Research and Planning Associate
Institutional Research and Planning
Cornell University / irp.cornell.edu
To manage your subscription to SPSSX-L, send a message to
LISTSERV@LISTSERV.UGA.EDU (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
For a list of commands to manage subscriptions, send the command