Validate if date is before date of current date

date, javascript

Solution

You can directly compare both dates as

return pickedDate <= todaysDate

For exact date comparison considering milliseconds you can use getTime() method

You can parse date as you have done:

pickedDatestr = "09-Apr-2010"
var pickedDate = new Date(Date.parse(pickedDatestr.replace(/-/g, " ")))

Problem

Using this function, I'm getting a 7 days difference; how can I test whether a date is before the current date? ``` function validateDate() { pickedDate = Date.parse("05-Jul-2012".replace(/-/g, " ")); todaysDate = new Date(); todaysDate.setHours(0, 0, 0, 0); dateDifference = Math.abs(Number(todaysDate) - pickedDate); //7 Days=604800000ms if (dateDifference > 604800000) { return false; } else { return true; } } ```

Original source