Need to find rows against a date

21 views
Skip to first unread message

Mohan Gudimetta

unread,
May 24, 2019, 8:44:52 AM5/24/19
to Google Apps Script Community
Hi,

I have some products data with expiry date for each product in my google sheet. Every day i want to check what are all the products that will expire in next day. I want to know how can i add one day to a date, below is my code but its not working. Its concatenating the days rather adding the number of days to a date.

    now = Utilities.formatDate(new Date(), "IST", "MM/dd/yyyy");
    var expDate = new Date(now + 1);
    
    //appdata = i am getting all the records to this varibale as a range
    for (i in appdata) 
    {
      var rec = appdata[i];
      if (rec[0] != "")
      {
        //expiry date in 8th column
appDate = Utilities.formatDate(rec[8], "IST", "MM/dd/yyyy");
        if (appDate == expDate)

<my code continues ...>


Any one please help me on this, i googled much couldn't find a solution ....

Eric Koleda

unread,
May 24, 2019, 10:18:13 AM5/24/19
to Google Apps Script Community
You can add a day to a date object like this:

date.setDate(date.getDate() + 1);

You'll need to do that before converting the date to a string using Utilities.formatDate().

- Eric

Clark Lind

unread,
May 25, 2019, 7:42:27 AM5/25/19
to Google Apps Script Community
I was having a date comparison problem yesterday. Do what Eric wrote, and also make sure there is no extra whitespace by using the .trim() function. There may be whitespace in your cells. 

    if (appDate.trim() == expDate.trim())

Mohan Gudimetta

unread,
May 28, 2019, 2:44:43 PM5/28/19
to google-apps-sc...@googlegroups.com
Solved my problem Eric, thank you so much for that

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-apps-script-community.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/c9e07b27-d28a-446e-8c84-8a48fc809f05%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages