Question

Retreive just the month from a date field


Badge +2

If I have a date field formatted as month-day-year is there a way to retreive just the month and use it in a tester? I want the user to input a month and then if it matches the month in the date field it will select all of those records. The data is in a geodatabase if that matters.


6 replies

Userlevel 3
Badge +26

You can use the AttributeSplitter to split the date field on "-". The first element in the list, _list{0}, will be the month.

Userlevel 4
Badge +36

Or maybe something like

@DateTimeFormat(@DateTimeParse(@Value(YourDateString),%N-%d-%Y),%N)

 

Userlevel 4
Badge +36

Or even with a StringSearcher, with the Regular Expression

^[^-]

 (Get all characters from the start of the string, up to the first dash)

StringSearcher_Month_first

Badge +2

You can use the AttributeSplitter to split the date field on "-". The first element in the list, _list{0}, will be the month.

You must have deleted your first suggestion which was to use @DateTimeFormat(@Value(date), %m) to extract the month. I used that and it worked perfectly! Thanks! I never tried your other suggestions as this one did the job!

Userlevel 3
Badge +26

You must have deleted your first suggestion which was to use @DateTimeFormat(@Value(date), %m) to extract the month. I used that and it worked perfectly! Thanks! I never tried your other suggestions as this one did the job!

Ha! I initially answered without testing. When I was testing, it wasn't acting as I thought so I deleted it. But never-the-less, glad it worked for you 😁

Userlevel 1
Badge +10

If reading from a geodatabase, you could use a where clause in a feature reader,  and set the numbered month with a user parameter so only those records are read which match the month selected

e.g.

 

EXTRACT(MONTH FROM "datefield") =$(month)

 

Reply