Comparing ONLY times in the DateTime variables

Hi all, I am still new to mendix and currently I am trying to compare a time variable between two other time values. Here is what I put as my check expression. parseInteger(formatTime($Appointment/ApptTime)) >= parseInteger(formatTime($IteratorCalendarEvent/StartDate)) and parseInteger(formatTime($Appointment/ApptTime)) <= parseInteger(formatTime($IteratorCalendarEvent/EndDate)) I tried different ways of trying to compare the times like 9:30 am > 1:00 PM. However, I have no clue to get that. I know the above expression gives me an error because I cannot turn "9:30 AM" to an integer or float but I am not sure what else I could do to get the result I want. I am not sure what other functions I could use to get what I need, I tried most....Any advice? Thanks
4 answers


If you want to compare only the time part of the date variables then reduce the variables to minutes. create 2 variables for the minutes by: parseInteger(formatDateTime($Appointment/ApptTime, 'HH'))* 60+parseInteger(formatDateTime($Appointment/ApptTime, 'mm') With the statement above you'll get the hours from $Appointment/ApptTime, multiplied with 60 and add the minutes of $Appointment/ApptTime to get the minutes from the start of the date. Do the same thing for the other variable and then compare the two.


I think you can use the formatDateTime function to output the time part in a format that is suitable for textual comparison. Note: untested code ahead.

formatDateTime($Appointment/ApptTime, 'HH:mm') >= 
formatDateTime($IteratorCalendarEvent/StartDate) and
formatDateTime($Appointment/ApptTime, 'HH:mm') 

The HH make sure that the hours are represented in 24 hour notation with two digits (see also our documentation and the table here ). mm does the same for minutes. So, the times in your example will look like "09:30" and "13:00". These can then be compared textually for the desired result.


Could you simply store your times in a datetime attribute that only ever addresses/edits the time portion of the variable? If so, you should just be able to directly compare your variables, as the date portion of the variable will remain at its default.


You can make use of the minutesBetween()

var1 = StartTime
var2 = EndTime

var3 = RandomDateVariable

x= round(minutesBetween(trimToDays(var1),var1))          gives the minutes between StartTime and the beginning of that day

y = round(minutesBetween(trimToDays(var2),var2))        gives the minutes between EndTime and the beginning of that day

z = round(minutesBetween(trimToDays(var3),var3))

now z should be between x and y to be true


I have rounded the bunch because float is depricated