0

I have a tab in sheets that collects dates from a scheduling application. All the values in Appointments!C:C are dates. I am trying to bring those dates to another tab, but some of the values seem to be converting into non-dates, while some stay as dates.

i am using the following script:

  if(AppWO==OpenWO) 
      {
       var Appdate1 = new Date(AppRange[i][3]) // this gets the date value from sheet ss1
        var DateString1 = ("0" + Appdate1.getDate()).slice(-2) + "-" + ("0"+(Appdate1.getMonth()+1)).slice(-2) + "-" + Appdate1.getFullYear() //this breaks up and reforms the value
       ss0.getRange(j+2,24,1,1).setValue(DateString1)  //this puts the date in sheet ss0
      }

The problem is that 'DateString1' on sheet ss0 seems to not always be a date value. Do I need to do something differntly to use setValue() when working with dates?

Carlo B.
  • 119
  • 2
  • 16
  • 2
    To get the date as it is displayed in the sheet you need to use `getDisplayValues` instead of `getValues` when you get the dates. – Marios Mar 10 '21 at 22:22
  • 1
    And if you want to create a date with a specific format then you can use dateformat : https://stackoverflow.com/a/29614252/11225291 – Marios Mar 10 '21 at 22:37
  • Hi there @CarloB.! I strongly suggest you to take the approach commented by @Mario. Could you please test it and share your findings? – Jacques-Guzel Heron Mar 11 '21 at 09:42
  • Mario, thanks so much!! that tiny detail has been causing me a ton of problem here, and on other scripts! much appreciated. This was indeed the problem, as the getDisplayValues() grabs what I see in the spreadsheet which may differ from the actual value of the cell. – Carlo B. Mar 11 '21 at 15:10

0 Answers0