Quick question on Date operations

Hello!

I have seen the below code:

MONTH([Date Field]) <= CURRENT_TIMESTAMP

I would like to ask, is this really valid?

From what I know, MONTH() returns and integer so how can an integer be compared with CURRENT_TIMESTAMP which is a full date and time value?

Also, even this comparison is correct, does it really return all the values in [Date Field] where the month is less than the current month or does it return the months that are less than the current month of current year?

Thanks!

No, it's not valid, for the reason you mentioned. If it did return results, they would be suspect/invalid.

It is not valid - but it will not fail due to implicit conversions and precedence. The function MONTH will return an integer value - that will then be implicitly converted to a datetime - and that value would then be compared with current_timestamp.

This will return all rows - because integer datetimes 1 through 12 will be 1900-01-02 through 1900-01-13 which will always be less than current_timestamp.

2 Likes