3
votes

I have a column in a Google Spreadsheet that displays dates. The sheet was originally created in Excel, then copied to Google. The column of dates was originally filled using a 7 day step; each date is a Sunday. In the spreadsheet, it is formatted M/D/YYYY (7/5/2015).

I am working on a script wherein the user selects a date cell, and a group of documents is generated based on the information in the subsequent columns of the row that contains the selected date.

The problem is that when the script pulls the value from the date cell, an integer is received, not a date, and thus I cannot use the date as part of the custom documents. (The integer is indeed representative of the correct date when I use the TO_DATE(value) function in another cell, but that function does not work in the script.)

Does anyone know how to convert the integer into a date inside of the script? Is there a function out there that someone has already written?

Thank you very much.

2

2 Answers

-1
votes

Have you tried to use the javascript object of Date? Something like that should work for you:

var dateVal = new Date(yourCellUnixTimeValue)
6
votes

The value you are seeing is the number of days since December 30, 1899. To convert this to a date you can create a new date on December 30, 1899 and add the value to it:

var myDate = new Date(1899, 11, 30);
myDate.setDate(myDate.getDate() + value);