I want to write a JavaScript to compare today's date with one field in a MsSql database assuming that the field name is "document_issuedate" and put this condition.
if today's date - document_issuedate > 30 then alert
I want to write a JavaScript to compare today's date with one field in a MsSql database assuming that the field name is "document_issuedate" and put this condition.
if today's date - document_issuedate > 30 then alert
How to calculate date difference in javascript
This question is similar, and appeared after a quick search. Basically, as long as you make the dates into a date object you can simply just subtract them like you've shown
Edit
Here's a better link then with more explanations and the appropriate snippet from that page. The oneDay variable is just there for convenience. The date objects are in Y,m,d format. Using getTime() on the date objects makes it so the difference gives a numeric value (in milliseconds) instead of a date object. Then dividing it by oneDay converts the milliseconds into days which is what you want. Math.abs makes sure you always have a positive number difference and Math.round makes it a whole number instead of a decimal
How to calculate the number of days between two dates using JavaScript?
var oneDay = 24*60*60*1000; // hours*minutes*seconds*milliseconds
var firstDate = new Date(2008,01,12);
var secondDate = new Date(2008,01,22);
var diffDays = Math.round(Math.abs((firstDate.getTime() - secondDate.getTime())/(oneDay)));