How would I achieve the pseudo-code below in JavaScript? I want to include the date check in the second code excerpt, where txtDate is for the BilledDate.
If ABS(billeddate – getdate) > 31 then yesno “The date you have entered is more than a month from today, Are you sure the date is correct,”. if (txtDate && txtDate.value == '') { txtDate.focus(); alert('Please enter a date in the 'Date' field.') return false; }
Generally speaking you work with Date-objects in javascript, and these should be constructed with the following syntax:
Beware, the month-part is an index, so january is 0, february is 1 and december is 11 !-)
Then you can pull out anything you want, the .getTime() thing returns number of milliseconds since start of Unix-age, 1/1 1970 00:00, så this value you could subtract and then look if that value is greater than what you want:
This will return a decimal number, so probably you’ll want to look at the integer-value: