Changing time from 24h to 12h

183 views
Skip to first unread message

Nicole H

unread,
Jan 28, 2021, 10:06:57 AM1/28/21
to Google Apps Script Community
I have a Google sheet with about 15-20 sheets and when I import the data daily it automatically comes across in 24h format. Is there an app script or a simplistic way to change every sheet to 12h format? If it matters or if it makes it easier it’s row 3 down to last row , and only columns D & L.

Any assistance or pointing me to the right direction would be appreciated

Bennett, Scott

unread,
Jan 28, 2021, 10:16:36 AM1/28/21
to google-apps-sc...@googlegroups.com
You could change the date format in the columns.  Or you can use setNumberFormat() in Apps script.

On Thu, Jan 28, 2021 at 9:07 AM Nicole H <lucky...@gmail.com> wrote:
I have a Google sheet with about 15-20 sheets and when I import the data daily it automatically comes across in 24h format. Is there an app script or a simplistic way to change every sheet to 12h format? If it matters or if it makes it easier it’s row 3 down to last row , and only columns D & L.

Any assistance or pointing me to the right direction would be appreciated

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/40666d12-adb5-4d20-9d17-c58f194c5ca4o%40googlegroups.com.


--
Scott Bennett
Data and Assessment Coordinator/Math Teacher
Bradley-Bourbonnais Community High School

Ed Sambuco

unread,
Jan 28, 2021, 10:50:35 AM1/28/21
to Google Apps Script Community
Your question is a bit more complicated than you might think,

It depends on the format of the date in the spreadheets you get.

If the input date cellls are formatted as strings, your best option is to fashion the strings so  that you can construct a date object out of it in app script.

Since you apparently want a timestamp value rather than just a date (format DateTime), then the data should already be a date object in the cells.

Either way, you need to start out with a date object.  Retrieve the cell(s) with getValue()  NOT getDisplayValue(), and then stringify it to whatever format you want with Utilities.formatDate().

Ed Sambuco

unread,
Feb 3, 2021, 10:19:54 AM2/3/21
to Google Apps Script Community
Actually, ther is a way to do this within the sheet ... go to Format ==.> Number ==> More options == More date and time options,  You can then edit as needed.


On Thursday, January 28, 2021 at 10:06:57 AM UTC-5, Nicole H wrote:
Reply all
Reply to author
Forward
0 new messages