Create date with current year to compare

0
Hi lovely mendix family! I want to calculate the current study year (as it starts in september and ends in august the next year). I want to compare the currentdatetime to a datetime with a variable in it. I tried: if [%CurrentDateTime%] < dateTime($HuidigJaar, 9, 1) then $VorigJaar else if [%CurrentDateTime%] > dateTime($HuidigJaar, 8, 31) then $VolgendJaar else empty   $HuidigJaar is an integer I got form the community commons java action call GetIntFromDateTime and is the current year. I want to use dateTime to create the date, but he expects literal integers. So do you know how to create a dateTime with a variable, or another solution to compare CurentDateTime to another dateTime with a dynamic year?   Thanks in advance!
asked
3 answers
2

Hi Lisa,

 

You could use the following to test if your current day/time is before or after september of the current year:

if [%BeginOfCurrentDay%] < addMonths(trimToYears([%BeginOfCurrentDay%]),9) then
    2018
else
    2019
 

Cheers,

 

John

 

answered
1

The function dateTime returns a string. Which tripped your first attempt.

For clarity first use activity CreateVariable to get

$StartOfNextCollegeYear = addMonths(trimToYears([%BeginOfCurrentDay%]),9) 

Then get the current collegeYear via:

if [%BeginOfCurrentDay%] < $StartOfNextCollegeYear then
     $HuidigJaar  – 1
else
     $HuidigJaar

 

answered
1

I used:

if [%CurrentDateTime%] < parseDateTime(toString($HuidigJaar)+ '-09-01', 'yyyy-MM-dd')
then $VorigJaar
else if [%CurrentDateTime%] > parseDateTime(toString($HuidigJaar) + '-08-31', 'yyyy-MM-dd')
then $VolgendJaar
else empty

and that works! If someone has a better practice for me, please let me know!

answered