Home > Back-end >  How to convert Date and Time with mailmerge google slides from sheets as it is in cell
How to convert Date and Time with mailmerge google slides from sheets as it is in cell

Time:01-31

enter image description here

I have created a table with which I can record our check in times of our employees with the help of a generated Qr code in each line.The data in the table is generated as slides and converted into pdf. For this I use a script that I got to work with your help and it works. Here I would like to thank you especially @tanaike.

My problem is that the date and time are not copied to the slides to be generated as indicated in the cell but completely with Central European time and I added in the script to look in column if its empty to generate the slide. If it's not empty don't do anything. As I said everything is working except this two things.

I must confess I did not try to correct it somehow because I had already shot the script and I made some here despair. It would be really great if you write me the solutions and I can take them over. I will share the spreadsheet with you and the screenshot with ae and time. Thanks for your time and effort to help people like us; we are really trying.

CodePudding user response:

function todaysDateAndTime() {
  const dt = Utilities.formatDate(new Date(),Session.getScriptTimeZone(),"MM:dd:yyyy");
  const tm = Utilities.formatDate(new Date(),Session.getScriptTimeZone(),"HH:mm:ss");
  Logger.log(dt);
  Logger.log(tm);
}

CodePudding user response:

As another approach, when I saw your question, I thought that if your Spreadsheet has the correct date values you expect, and in your script, you are retrieving the values using getValues, getValues is replaced with getDisplayValues(), it might be your expected result.

When I saw your provided sample Spreadsheet, I found your current script, when your script is modified, how about the following modification?

From:

var sheetContents = dataRange.getValues();

To:

sheetContents = dataRange.getDisplayValues();

Note:

  • When I saw your sample Spreadsheet, it seems that the column of the date has mixed values of both the string value and the date object. So, if you want to use the values as the date object using getValues, please be careful about this.

Reference:

  • Related