1
votes

I have a Google form to collect info on people leaving the organisation. One of the questions is 'What date and what time do they leave' The response is in the format dd/mm/yyyy, hh:mm. so a typical response would be 24/04/2015 17:00:00, and that's what I see in the Form responses 1 worksheet when the form is submitted.

I need to add the day of the week and copy the information into another worksheet within the spreadsheet, so I use

var leaveDate = inputSheet.getRange("G" + lastRow).getValue();  
var leaveDateTime = Utilities.formatDate(leaveDate, "GMT", "EEE dd-MM-yyyy hh:mm:ss");

The issue I'm seeing is that when I paste the value the time is changing, and what gets pasted is

Fri 24-04-2015 04:00:00

Can anyone explain why this is happening and what I can do to resolve it?

Thanks

3

3 Answers

0
votes

Apps Script converts date types to the time zone set up in the script editor. In the script editor, you need to set the time zone, even if you've set it in the spreadsheet.

Project Properties

Set the time zone to your local time zone.

Time Zone

Make sure the time zone in your spreadsheet, and the time zone in your script editor match.

If you have multiple editors of the spreadsheet in multiple time zones, and the other users have set the time to their local time, then obviously, their time and your time won't be the same. If someone left the organization on the other side of the world, at 4pm their time, they didn't leave the organziation at 4pm your time. You could assume that if the spreadsheet states 4pm, that it was their local time, and convert the time. In that case, you'd need to know the time zone of every time entry that is made, and then adjust it as necessary.

0
votes

Try:

...
// var leaveDateTime = Utilities.formatDate(leaveDate, "GMT", "EEE dd-MM-yyyy hh:mm:ss");
   var leaveDateTime = Utilities.formatDate(leaveDate, "GMT", "EEE dd-MM-yyyy HH:mm:ss");
...

UPDATE

enter image description here

0
votes

Thanks to @sandy-good and @wchiquito for pointing me in the right direction. There were 2 issues. First issue is using hh instead of HH. The second issue is that we are on GMT+1 at the moment, and will be until end October, at which point we go back to GMT! As I don't want to code around that I'm going to simplify it by dropping the day, which then means I don't have to reformat the date.