0

I have a column contain a date in "Sep -13" format.

When I access it from code, it gives integer value. How can I get a date object?

If I use "dd/mm/yyyy" format in sheet, it gives me date object.

function check()
{
  var source = SpreadsheetApp.openById('sheet id');
  var sourcesheet = source.getSheetByName('sheet name');   
  var tt = sourcesheet.getRange('F700').getValue();
   debugger;
}

Result: enter image description here

1
  • I tried replicating your issue. If I click the column heading, and make the entire column a date format, I get a date in the code. If I format the entire column as a number, I get a number. So, I was not able to duplicate your issue. Commented Apr 8, 2016 at 20:23

1 Answer 1

1

That cells original value might be an integer. That could be happen if you copy and paste values only for a date. so .getValue() will give you that number.

You can use that number to create a date object. JavaScript dates can be constructed by passing milliseconds

//base date 01/01/1970 integer value :25569 
//excelDate your date in integer

var myDate = new Date((excelDate - 25569)*86400*1000);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.