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); }
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.
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.
Utilities.formatDate(new Date(), "GMT+1", "dd/MM/yyyy")
You can change the format by doing swapping the values.
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 }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With