Select to view content in your preferred language

Exporting to PDF with a Unique Name

1132
5
Jump to solution
05-30-2013 05:47 AM
joshwheeler1
Emerging Contributor
Hello,

I have a script that exports my .mxd to a .pdf and a .png and I would like to add a Unique Name to the exported maps so everytime the script runs the exports don't get overwritten.

I would like to have the date included in the exported documents name. My idea was to add time.asctime() to the title but I can't seem to get that to work.

Any ideas would be very appreciated.

Thanks,
Josh
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
MathewCoyle
Honored Contributor
I usually do something like this.

stamp = datetime.datetime.now().strftime("%Y_%M_%d_%H%M%S")

View solution in original post

0 Kudos
5 Replies
MathewCoyle
Honored Contributor
I usually do something like this.

stamp = datetime.datetime.now().strftime("%Y_%M_%d_%H%M%S")
0 Kudos
joshwheeler1
Emerging Contributor
Just what I needed, thanks a lot.
0 Kudos
RhettZufelt
MVP Notable Contributor
That works if you want year_Minutes_day_hour_minutes_seconds.
If you want Month_Day_year, something like this works:

>>> from time import strftime
>>> stamp = datetime.datetime.now().strftime("%Y_%M_%d_%H%M%S")
>>> stamp
'2013_56_30_155604'
>>> 
>>> dt = strftime("%m_%d_%Y %H:%M:%S")
>>> dt
'05_30_2013 15:56:17'
>>> 
>>> dt = strftime("%m_%d_%Y")
>>> dt
'05_30_2013'


R_
0 Kudos
MathewCoyle
Honored Contributor
Ah yes small typo, rhett is right, should be %m for month. Though date formats are always year_month_day.
0 Kudos
RhettZufelt
MVP Notable Contributor
strftime actually has a bunch of directives you can use.  See here for the list http://www.tutorialspoint.com/python/time_strftime.htm

R_
0 Kudos