Skip to main content
Question

Retreive just the month from a date field

  • May 18, 2022
  • 6 replies
  • 672 views

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+31
  • Influencer
  • 627 replies
  • 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+58
  • Evangelist
  • 932 replies
  • May 18, 2022

Or maybe something like

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

 


geomancer
Evangelist
Forum|alt.badge.img+58
  • Evangelist
  • 932 replies
  • 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
  • 32 replies
  • 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.

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+31
  • Influencer
  • 627 replies
  • May 18, 2022

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+44
  • Influencer
  • 3422 replies
  • 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)