Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get today date in google appScript

How do I get the Today date on google appscript?

I need to write a code to input today´s date in a cell.

function changeDate(){   var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(GA_CONFIG);   var date = //Today´s date!?!?!!?   var endDate = date;    sheet.getRange(5, 2).setValue(endDate);   } 
like image 839
user3347814 Avatar asked Jul 22 '14 18:07

user3347814


People also ask

How do I get todays date in Google script?

The TODAY function in Google Sheets returns the current date. You can use it to automatically update the date in a spreadsheet cell, or to calculate the age of a person based on their date of birth. To use the TODAY function, type =TODAY() in a cell and press Enter.

How do I get the current date and time in an app script?

Easiest way, you can use javascript date object which is new Date(). But then you will get the whole time object. You just need to change the format in spreadsheet to time or date, whatever you like.


1 Answers

Utilities.formatDate(new Date(), "GMT+1", "dd/MM/yyyy") 

You can change the format by doing swapping the values.

  • dd = day(31)
  • MM = Month(12) - Case sensitive
  • yyyy = Year(2017)
function changeDate() {     var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(GA_CONFIG);     // You could use now Date(); on its own but it will not look nice.     var date = Utilities.formatDate(new Date(), "GMT+1", "dd/MM/yyyy")     var endDate = date } 
like image 169
Haytch Avatar answered Sep 20 '22 06:09

Haytch