5554
Views
8
Comments
Solved
How to compare two dates?
Question

I need to compare two dates in entity filter. How to do it? 

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP
Solution

To clarify some of the above posts, for some reason it's not possible to use the "greater than", "greater than or equal to", "less than" and "less than or equal to" operators when you compare a Variable of type Date with a Variable of type Date Time. It is possible to compare a Date and a Date Time with the "equal" operator, however.

As has been mentioned above, to overcome this, simply convert the Date Variable to a Date Time by using the built-in DateToDateTime() Function.

And as Behavioral mentioned, since the NullDate() is actuall 1900-01-01, it also compares like that (i.e. NullDate will always be less than a valid, contemporary, date).

2012-03-16 12-21-09
João Rosado
Staff

Hi Brajesh,


What is your doubt there?
You can compare dates with the usual "<" ">"  "="  "<>" operators, just like any other attribute type.

UserImage.jpg
Chris DeFord

Hello I am in need of some assistance I need to subtract the date they put in the input calender minus the current date to figure out how old they are can someone please help me with this.


2019-11-12 17-31-26
Justin James
 
MVP

Use DiffDays, DiffMinutes, etc. to compare dates.

J.Ja

2014-10-21 20-15-17
Alberto Ferreira

Hello

The Justin solution works, however we can not use João Rosado solution

2019-08-15 01-24-09
Katia Cibele

Alberto Ferreira wrote:

Hello

The Justin solution works, however we can not use João Rosado solution

Hello, 

Try 

SyntaxEditor Code Snippet

DiffDays( DateTimeToDate( date ) ,  otherDate))



2020-05-13 16-43-32
Mihai Runcan

Alberto Ferreira wrote:

Hello

The Justin solution works, however we can not use João Rosado solution

João Rosado solution WORKS if you compare 'Date Time' with 'Date Time' ot 'Date with 'Date', you can also convert 'Date' to 'Date Time' or reverse. It is the easiest way to compare two dates using  < > =.


2020-06-08 02-42-28
Wasabi

Hi,

Just want to warn that null date is 01-01-1900. You can use nulldate() to compare in this case. 

Please be careful!!!

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP
Solution

To clarify some of the above posts, for some reason it's not possible to use the "greater than", "greater than or equal to", "less than" and "less than or equal to" operators when you compare a Variable of type Date with a Variable of type Date Time. It is possible to compare a Date and a Date Time with the "equal" operator, however.

As has been mentioned above, to overcome this, simply convert the Date Variable to a Date Time by using the built-in DateToDateTime() Function.

And as Behavioral mentioned, since the NullDate() is actuall 1900-01-01, it also compares like that (i.e. NullDate will always be less than a valid, contemporary, date).

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.