Raghav
Raghav

Reputation: 53

Retrieving date value from google doc gives me strange values

I am trying to read a column value which has date in mm/dd/yyyy format, but I am getting strange values when i use the below script.

var data = spreadsheet.getDataRange().getValues();
for(i in data){
  Logger.log(data[i][4]);
}

The column value in the doc is 1/24/2015 but i get 42028.0 from the above script.

Upvotes: 0

Views: 75

Answers (2)

Hann
Hann

Reputation: 713

If you want a specific format for a date.

Code

 var formattedDate = Utilities.formatDate(new Date(), "GMT", "MM-yyyy-dd");
 Logger.log(formattedDate);

Logger

[15-02-24 16:52:51:958 CET] 02-2015-24


API for more informations: https://developers.google.com/apps-script/reference/utilities/utilities

Upvotes: 1

Kriggs
Kriggs

Reputation: 3778

Those are the number of days passed since Jan. 1st 1900, Javascript way of keep track, just convert it back to a date with var currDate = new Date( data[i][4] ).

Upvotes: 0

Related Questions