I'm tasked with writing a web portal for a legacy application that was written in Visual Foxpro. I have to validate a pregnancy due date. The rule is that it can't be more than 9 months from the current date. I've already tried to argue that this is too vague and that it needs to be in days or weeks, but I was told that I have to mimic the legacy software.
Here's what the code in VSP is doing:
maxValueForDueDate = GOMONTH(DATE() , 9)
According to MSDN GOMONTH()
handles edge cases as follows:
SET CENTURY ON
STORE GOMONTH({^1998-02-16}, 5) TO gdDeadLine
CLEAR
? gdDeadLine && Displays 07/16/1998
? GOMONTH({^1998-12-31}, 2) && Displays 02/28/1999
? GOMONTH({^1998-12-31}, -2) && Displays 10/31/1998
As you can see adding 2 months to December 31st does not result in March 2nd, unfortunately that's exactly what the following javascript does:
var dDate = new Date('1998-12-31');
dDate.setMonth(dDate.getMonth() + 2);
alert(dDate.toDateString()); // results in - Tue Mar 02 1999
Does anyone have a javascript function handy that they've written for this scenario? I've googled around, but haven't found what I need. I'm limited in my third-party usage to JQuery.