Adde LD
Adde LD

Reputation: 3

How to set today's date and time when pressing a button

I've been following this guide https://www.youtube.com/watch?v=fj3ALXI90-Q

But I want the date and time displayed in another way. This is what I want to happen when I press the button:

8/31/2019 9:49:23

But this is what displays 2019-08-31 14.45.29 which I know it's not too far from what I want, but it still isn't the way I want it displayed. Heres the code. I Would appreciate if I could get the whole code so I just can copy and paste due to my lack of knowledge in coding.

function setNow() {
  SpreadsheetApp.getActiveRange().setValue(new Date());
}

Upvotes: 0

Views: 372

Answers (1)

player0
player0

Reputation: 1

instead of:

new Date()

try using:

Utilities.formatDate(time, "GMT+5", "M/d/yyyy, h:mm:ss");

see: https://developers.google.com/apps-script/reference/utilities/utilities#formatDate(Date,String,String)

Upvotes: 1

Related Questions