0
$\begingroup$

I'm working with dates in the form, e.g.,

t1 = {2017,4,17}    and    
t2 = {2017,4,3}. 

I want to execute commands like

If[t1 == t2, Print["Right!"], Print["Wrong!"]];

This works, but, the following doesn't.

If[t1 >= t2, Print["Right!"], Print["Wrong!"]];

What "comparison commands" can I use to achieve common <=, < , >, >=, and != functionality?

$\endgroup$
2
$\begingroup$

You cannot compare lists directly, unless they are equal, or you will get the expression unevaluated.

You can use the build in DateObject for such comparison.

DateObject[{2017, 4, 17}] > DateObject[{2017, 4, 3}]
(*True*)

Please read the documentation for more usages.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.