Skip to main content
Question

Retreive just the month from a date field


Forum|alt.badge.img+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

dustin
Influencer
Forum|alt.badge.img+30
  • Influencer
  • May 18, 2022

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


geomancer
Evangelist
Forum|alt.badge.img+47
  • Evangelist
  • May 18, 2022

Or maybe something like

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

 


geomancer
Evangelist
Forum|alt.badge.img+47
  • Evangelist
  • May 18, 2022

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


Forum|alt.badge.img+2
  • Author
  • May 18, 2022
dustin wrote:

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!


dustin
Influencer
Forum|alt.badge.img+30
  • Influencer
  • May 18, 2022
chris28 wrote:

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 😁


ebygomm
Influencer
Forum|alt.badge.img+33
  • Influencer
  • May 18, 2022

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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings