How to select the rows based on the the date field which are in last 7 days before today's date?

680
1
Jump to solution
07-26-2017 12:54 PM
ManjariGoyal
New Contributor III

Hi,

I am using the Select by attribute tool to select the records. I have a date field name T: (A 1305) Site Walk-Finish so I need to select only those records which has the date (T: (A 1305) Site Walk-Finish) which are in last 7 days of today's date. I am not sure how to write the expression.

Thanks

0 Kudos
1 Solution

Accepted Solutions
JayantaPoddar
MVP Esteemed Contributor

I am sure there will be easier methods.

You can do the following steps.

1. Add a New Field in the attribute table with Date datatype.

Using Field Calculator (Python Parser), write the following expression for current date

datetime.datetime.now( )

2. In Select by Attribute, write the following expression

Date_Orig > Date_Now - 7

where Date_Orig is the original Date Field

Date_Now is the Current Date Field.

N.B.: I executed the above expressions in ArcMap, as I am not having ArcGIS Pro at the moment.



Think Location

View solution in original post

1 Reply
JayantaPoddar
MVP Esteemed Contributor

I am sure there will be easier methods.

You can do the following steps.

1. Add a New Field in the attribute table with Date datatype.

Using Field Calculator (Python Parser), write the following expression for current date

datetime.datetime.now( )

2. In Select by Attribute, write the following expression

Date_Orig > Date_Now - 7

where Date_Orig is the original Date Field

Date_Now is the Current Date Field.

N.B.: I executed the above expressions in ArcMap, as I am not having ArcGIS Pro at the moment.



Think Location