{"id":2463,"date":"2017-01-31T13:11:15","date_gmt":"2017-01-31T02:41:15","guid":{"rendered":"https:\/\/davidkeen.com\/blog\/?p=2463"},"modified":"2025-10-23T10:47:35","modified_gmt":"2025-10-23T00:17:35","slug":"time-zone-conversion-in-google-sheets","status":"publish","type":"post","link":"https:\/\/davidkeen.com\/blog\/2017\/01\/time-zone-conversion-in-google-sheets\/","title":{"rendered":"Time zone conversion in Google Sheets"},"content":{"rendered":"\n<p>Google Sheets does not have a built in way of converting time zone data but by using the power of <a href=\"http:\/\/momentjs.com\/\">Moment.js<\/a> and Google&#8217;s script editor we can add time zone functionality to any sheet.<\/p>\n\n\n\n<p>First, we need to add the Moment.js code as a library that can be shared between different documents. This is the javascript library that adds date and time zone manipulation support. A good way to do this is to create it from Google Drive so it can be easily edited and shared with all your sheets.<\/p>\n\n\n\n<p>In Google Drive, go to New &gt; More &gt; Connect more apps and choose Google Apps Script. Now, create a new Google Apps Script document. This will open the Google script editor. Call the project &#8216;Moment&#8217; and create two files in the project called moment.js and moment-timezone.js using the <a href=\"http:\/\/momentjs.com\/\">moment<\/a> and <a href=\"http:\/\/momentjs.com\/timezone\/\">moment-timezone<\/a> libraries. Make sure you choose one of the moment-timezone files with time zone data. You should end up with a project something like this:<\/p>\n\n\n\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button is-style-fill\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/docs.google.com\/spreadsheets\/d\/1M9DUrAf1IzBmp_59y-UZYZGkTAMj5w15lCO8flyZRS0\/edit?usp=sharing\" target=\"_blank\" rel=\"noreferrer noopener\">View the demo sheet<\/a><\/div>\n<\/div>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><a href=\"https:\/\/i0.wp.com\/davidkeen.com\/blog\/wp-content\/uploads\/2017\/01\/Screenshot-2017-01-30-15.29.30.png?ssl=1\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" width=\"1400\" height=\"1000\" data-attachment-id=\"2464\" data-permalink=\"https:\/\/davidkeen.com\/blog\/2017\/01\/time-zone-conversion-in-google-sheets\/screenshot-2017-01-30-15-29-30\/\" data-orig-file=\"https:\/\/i0.wp.com\/davidkeen.com\/blog\/wp-content\/uploads\/2017\/01\/Screenshot-2017-01-30-15.29.30.png?fit=1400%2C1000&amp;ssl=1\" data-orig-size=\"1400,1000\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"moment.js\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/davidkeen.com\/blog\/wp-content\/uploads\/2017\/01\/Screenshot-2017-01-30-15.29.30.png?fit=1024%2C731&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/davidkeen.com\/blog\/wp-content\/uploads\/2017\/01\/Screenshot-2017-01-30-15.29.30.png?resize=1400%2C1000&#038;ssl=1\" alt=\"\" class=\"wp-image-2464\"\/><\/a><\/figure>\n\n\n\n<p>To easily use this in multiple sheets we can publish it as a library. Go to File &gt; Manage versions and save a new version. We are nearly finished here but before we move on go to File &gt; Project properties and make a note of the project key, you will need this to refer to your library in your sheets.<\/p>\n\n\n\n<p>In our test we are going to use our new library to convert times in a local time zone to UTC.<\/p>\n\n\n\n<p>Create a new Google sheet and enter a date in A1 and a time zone in B1, like this:<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><a href=\"https:\/\/i0.wp.com\/davidkeen.com\/blog\/wp-content\/uploads\/2017\/01\/Screenshot-2017-01-31-12.51.10.png?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"968\" height=\"432\" data-attachment-id=\"2466\" data-permalink=\"https:\/\/davidkeen.com\/blog\/2017\/01\/time-zone-conversion-in-google-sheets\/screenshot-2017-01-31-12-51-10\/\" data-orig-file=\"https:\/\/i0.wp.com\/davidkeen.com\/blog\/wp-content\/uploads\/2017\/01\/Screenshot-2017-01-31-12.51.10.png?fit=968%2C432&amp;ssl=1\" data-orig-size=\"968,432\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/davidkeen.com\/blog\/wp-content\/uploads\/2017\/01\/Screenshot-2017-01-31-12.51.10.png?fit=968%2C432&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/davidkeen.com\/blog\/wp-content\/uploads\/2017\/01\/Screenshot-2017-01-31-12.51.10.png?resize=968%2C432&#038;ssl=1\" alt=\"\" class=\"wp-image-2466\"\/><\/a><\/figure>\n\n\n\n<p>Go to Tools &gt; Script editor and create a project called Functions. In the script editor, go to Resources &gt; Libraries and using the project key you made a note of before add your Moment library and select version 1. I prefer to use a shorter identifier like &#8216;m&#8217;. Click save and your library is now accessible to your sheet&#8217;s script. We can create a function to convert to UTC like this:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>function toUtc(dateTime, timeZone) {\n  var from = m.moment.tz(dateTime, timeZone);\n  return from.tz(\"Etc\/UTC\").format('YYYY-MM-DD HH:mm:ss');\n}<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #81A1C1\">function<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">toUtc<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9\">dateTime<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">timeZone<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">  <\/span><span style=\"color: #81A1C1\">var<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">from<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">m<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #D8DEE9\">moment<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">tz<\/span><span style=\"color: #D8DEE9FF\">(<\/span><span style=\"color: #D8DEE9\">dateTime<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">timeZone<\/span><span style=\"color: #D8DEE9FF\">)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">  <\/span><span style=\"color: #81A1C1\">return<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">from<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">tz<\/span><span style=\"color: #D8DEE9FF\">(<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">Etc\/UTC<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #D8DEE9FF\">)<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">format<\/span><span style=\"color: #D8DEE9FF\">(<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">YYYY-MM-DD HH:mm:ss<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #D8DEE9FF\">)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ECEFF4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>Save your project and you can now use this function in your sheets like this:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>=toUtc(TEXT(A1, \"YYYY-MM-DD HH:mm:ss\"), B1)<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #d8dee9ff\">=toUtc(TEXT(A1, &quot;YYYY-MM-DD HH:mm:ss&quot;), B1)<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><a href=\"https:\/\/i0.wp.com\/davidkeen.com\/blog\/wp-content\/uploads\/2017\/01\/Screenshot-2017-01-31-13.00.13.png?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"858\" height=\"416\" data-attachment-id=\"2467\" data-permalink=\"https:\/\/davidkeen.com\/blog\/2017\/01\/time-zone-conversion-in-google-sheets\/screenshot-2017-01-31-13-00-13\/\" data-orig-file=\"https:\/\/i0.wp.com\/davidkeen.com\/blog\/wp-content\/uploads\/2017\/01\/Screenshot-2017-01-31-13.00.13.png?fit=858%2C416&amp;ssl=1\" data-orig-size=\"858,416\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/davidkeen.com\/blog\/wp-content\/uploads\/2017\/01\/Screenshot-2017-01-31-13.00.13.png?fit=858%2C416&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/davidkeen.com\/blog\/wp-content\/uploads\/2017\/01\/Screenshot-2017-01-31-13.00.13.png?resize=858%2C416&#038;ssl=1\" alt=\"\" class=\"wp-image-2467\"\/><\/a><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Google Sheets does not have a built in way of converting time zone data but by using the power of Moment.js and Google&#8217;s script editor we can add time zone functionality to any sheet. First, we need to add the Moment.js code as a library that can be shared between different documents. This is the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2503,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[25],"tags":[27],"class_list":["post-2463","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dev","tag-featured"],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/davidkeen.com\/blog\/wp-content\/uploads\/2017\/01\/pexels-photo-277458.jpeg?fit=1280%2C960&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/davidkeen.com\/blog\/wp-json\/wp\/v2\/posts\/2463","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/davidkeen.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/davidkeen.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/davidkeen.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/davidkeen.com\/blog\/wp-json\/wp\/v2\/comments?post=2463"}],"version-history":[{"count":9,"href":"https:\/\/davidkeen.com\/blog\/wp-json\/wp\/v2\/posts\/2463\/revisions"}],"predecessor-version":[{"id":2859,"href":"https:\/\/davidkeen.com\/blog\/wp-json\/wp\/v2\/posts\/2463\/revisions\/2859"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/davidkeen.com\/blog\/wp-json\/wp\/v2\/media\/2503"}],"wp:attachment":[{"href":"https:\/\/davidkeen.com\/blog\/wp-json\/wp\/v2\/media?parent=2463"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/davidkeen.com\/blog\/wp-json\/wp\/v2\/categories?post=2463"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/davidkeen.com\/blog\/wp-json\/wp\/v2\/tags?post=2463"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}