Forum Discussion
JavaScript help needed - Add 6 months to a date
Basically you just add the future day in your Date Object. Like this.
var someFutureDate = new Date('11/21/2023');
To format it as you want you have to repeat similar steps as you do in the above code.
However you can use builtin functionality of the Date Object to format it too.
I guess in the end you want to compare whether a date is past or not.
For that you need to use getTime() of the Date Object. It translates any given Date to a number of milliseconds that have passed since Januari 1 1970. And thus you then can compare 2 dates...
Like this.
// Compare the two dates using getTime() method and check if the given date is in the past
var currentDate = new Date();
var futureDate = new Date('11/22/2024 12:30 PM');
var pastDate = new Date('11/21/2021 18:30 PM');
if (futureDate.getTime() > currentDate.getTime()) {
}
if (pastDate.getTime() < currentDate.getTime()) {
}
getTime() returns a number like this 845337932000
Adding a simple sample Story.