Dynamic Text Today's Date +- Number of Days

2521
4
Jump to solution
04-29-2021 12:25 PM
BeccaBoyd
New Contributor II

I am trying to create a dynamic text box for today's date plus or minus a number of days. In ArcMap the Python string for the expression was:

(str( datetime.date.today() - datetime.timedelta(days=8))) + ' to ' + (str( datetime.date.today() - datetime.timedelta(days=2)))

I haven't been able to recreate this in Pro. It is for a map and report run daily where we want to have the date range listed as "Today - 8 days to Today - 2days", or 4/21/21 to 4/27/21 for today 4/29/21. 

Tags (1)
1 Solution

Accepted Solutions
JeffBarrette
Esri Regular Contributor

Becca, with a little digging and team help, the following may be your solution (without having to use a Python script to update the value).

On layout, insert Dynamic Text --> Value

Click on the Value to open the Insert Table Attribute dialog.

Set the table to be the index layer (doesn't really matter)

Click the expression button next to field

and set the expression to:

 

 

var relDate = Now();
var start = DateAdd(relDate, -8, "days");
var end = DateAdd(relDate, -2, "days");

Text(start, 'M/D/Y') + ' to ' + Text(end, 'M/D/Y');

 JeffBarrette_0-1619734445129.png

View solution in original post

4 Replies
JeffBarrette
Esri Regular Contributor

Hello Becca,

 

Can you please provide a screenshot of where you set this in ArcMap?  I tried in both ArcMap and Pro and could not get this to work. 

Jeff - arcpy.mp and Layout teams

BeccaBoyd
New Contributor II

Yes, for reference I did not make this map originally, but am trying to recreate/replicate in Pro. The text has this for properties 

BeccaBoyd_0-1619729091844.png

And then I found the "expression" in the Display Properties for the layer that the data driven pages runs off of. 

BeccaBoyd_1-1619729149013.png

Let me know if that isn't quite clear, or you need anything else, really appreciate the help!

JeffBarrette
Esri Regular Contributor

Becca, with a little digging and team help, the following may be your solution (without having to use a Python script to update the value).

On layout, insert Dynamic Text --> Value

Click on the Value to open the Insert Table Attribute dialog.

Set the table to be the index layer (doesn't really matter)

Click the expression button next to field

and set the expression to:

 

 

var relDate = Now();
var start = DateAdd(relDate, -8, "days");
var end = DateAdd(relDate, -2, "days");

Text(start, 'M/D/Y') + ' to ' + Text(end, 'M/D/Y');

 JeffBarrette_0-1619734445129.png

BeccaBoyd
New Contributor II

Thank you so much!! I think that did it.