I have a scenerio where I need to compare a date from an API response with today's date and check whether it is less than or equal.
The API response will give me a JSON object and in that JSON the key " License" will contain a date in the format "13-Aug-2019",I need to compare this date with today's date and if today's date is greater than "13-Aug-2019" gives a fail in the test results .
Below is the code I wrote to get the date in the license string and today's date,
Var body = JSON.parse(response Body); Var body date=body["license"] //Sample license value is " license cs code1 version 13-aug- 2018 cnts ......" var words = bodydate.split(' '); license_valid_till=words; // This will get the string 13-aug- 2019 console.log(license_valid_till) Var ts = new Date(); var part=ts.toDateString(); var dpart = part.split(' '); today_date=dpart + "-" +dpart +"-"+ dpart; //This will get the string 12-aug-2019 console.log(today_date)
Now my question is how can I compare this two values,any suggestions will be of great help?