I am looking for some help, trying to compare 2 dates in JavaScript, but haven’t managed to find the exact answer on this site yet.
I am only just starting out with JavaScript and I get the impression that getting the current date\time is not a simple 1 line of code which I thought it would be. I thought I could use a ternary operator but maybe not. I hope I’m wrong but here is my dilemma.
I want to compare 2 dates. If date1 is before date2 then do something. If not then do something else.
- date1: is the current date time. i.e. my system clock
- date2: is a predefined value. I already have this value in the web page: ${expiredDateTime.format(“ddMyyyyhm”) I believe date 2 is a string but I’m no expert on jquery.
Any help with this would be great.
Please try the below code: