ArcMap - Definition query using dates to select current week

822
2
Jump to solution
05-27-2020 10:01 AM
MaximeDemers
Occasional Contributor III

I would like to write a definition query expression to get features where a date field is in the current week (starting Sunday ending Saturday)

I have difficulties to imagine how using CURRENT_DATE would help me in that case.

I want the definition expression to returns the same features from Sunday to Saturday.

My feature class is stored in PostGreSQL (ArcGIS Enterprise)

0 Kudos
1 Solution

Accepted Solutions
MaximeDemers
Occasional Contributor III

The solution I have found with Postgres

EXTRACT(WEEK FROM mydatefield) = EXTRACT(WEEK FROM CURRENT_DATE) + 1 AND EXTRACT(YEAR FROM mydatefield) = EXTRACT(YEAR FROM CURRENT_DATE)

 

View solution in original post

0 Kudos
2 Replies
JoshuaBixby
MVP Esteemed Contributor

Some good discussion here:  how to get data of current week only in SQL server? - Stack Overflow .  The discussion is focused on SQL Server but Postgres also has a DatePart function (PostgreSQL: Documentation: 12: 9.9. Date/Time Functions and Operators ).

0 Kudos
MaximeDemers
Occasional Contributor III

The solution I have found with Postgres

EXTRACT(WEEK FROM mydatefield) = EXTRACT(WEEK FROM CURRENT_DATE) + 1 AND EXTRACT(YEAR FROM mydatefield) = EXTRACT(YEAR FROM CURRENT_DATE)

 

0 Kudos