LiranE Posted June 13, 2015 Share Posted June 13, 2015 Hi, I have this problem : I am using google script with sheets and I can't find a way to get the number of days between due date (from the sheet) and current date. I want to send alert when current date is less then 30 days from due date. maybe its related to the format of the date ? ( Sat Jun 13 2015 08:02:04 GMT+0300 (EEST)) please help, function CheckedDatesToAlert() { var sheet = SpreadsheetApp.getActiveSheet(); var data = sheet.getDataRange().getValues(); var sub = "Alert" ; var CurrentDate = new Date(); var email = Session.getActiveUser().getEmail(); for (var i = 1; i < data.length; i++) { var expireDate = data[6]; if (CurrentDate.toDateString() < expireDate.toDateString()) { var subject = sub ; Link to comment Share on other sites More sharing options...
justsomeguy Posted June 15, 2015 Share Posted June 15, 2015 You can use the Date.valueOf method or Date.getTime method to return the Unix timestamp for the date (in milliseconds). You can subtract them to get the difference between the dates, and then divide to get days, hours, minutes, etc. There are 86400000 milliseconds in a day (60 * 60 * 24 * 1000). Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now