0

I want an alert to pop up if today's date is greater than the date in cell data (Overdue date). So, I used "IF" statement in the Script but it's not working. Either today's date is greater, less or equal to the data date, the alert will always pop up. If the date is not overdue it should not pop up the alert message.

Image of the Sheet

function onOpen(e){
    var sh1=SpreadsheetApp.getActiveSpreadsheet();
    var test1=sh1.getSheetByName("3rdEdition-Pindaan1");
    var iso=SpreadsheetApp.getUi();

    var date=Utilities.formatDate(new Date(),"GMT+8","dd-MMM-yyyy");
    var d1=Utilities.formatDate(test1.getRange("F18").getValue(),"GMT+8","dd-MMM-yyyy");

    if (d1<=date)
    {
      iso.alert('Please update the outdated documents');
    }
}
John Kugelman
  • 349,597
  • 67
  • 533
  • 578
crono93
  • 3
  • 2
  • I think that the reason for your current issue is that you are comparing the string value. So, please modify `date` and `d1` to `var date=new Date().getTime()` and `var d1=test1.getRange("F18").getValue().getTime()`, respectively, and test it again. In this modification, the date is compared as the Unix time. By the way, in your situation, do you want to check only the cell "F18"? – Tanaike Jan 31 '23 at 04:53
  • Sir Tanaike, you are a life savior. It worked ! Thank you very much ! Yes I want to try for one cell first. The rest would be no problem. Much appreciated sir. – crono93 Jan 31 '23 at 06:34
  • Thank you for replying. I'm glad your issue was resolved. From your reply, I flagged your question as a duplicate question. – Tanaike Jan 31 '23 at 06:36

0 Answers0