Google Docs: How to Insert Date and Time (Macro)

If you are from the world of Microsoft Word users, inserting date/time is a cakewalk – and you know that already.

But in Google Docs, there is no straight-forward way to insert date or time into our Google Docs file.

To do that, we need to use the Google’s in-built Script Editor.

Let’s begin, and by the end of this blog post, you’d be able to simply click on a menu item to insert your current date or time, or even date in the long date format.

One quick note before we begin – here’s a video version of this blog post in case you wanted to see a quick (< 3 min) demo of how to insert date or time into your Google Docs file.


Subscribe to Tech Library TV  


If the video didn’t play or you need more instructions, you can continue reading…

After you open your blank Google Docs file (remember this script works only on your current document, not on all your Docs files), go to Tools > Script Editor.

Tools%20script%20editor

A blank ‘Untitled project’ opens with the Code.gs file ready to be edited.

You can simply remove all the existing code (nothing but an empty function).

Now go to my GitHub Gist (simply click the link to open in a new tab auto-magically) to copy and paste this code snippet into your Code.gs (script editor) OR alternatively simply copy and paste from the code below.

That’s all – you’ll now see a new menu called ‘Utilities‘ and three new menu items within that menu – one for each of the following:

  • Insert Date
  • Insert Time
  • Insert Long Date
Utilities%20menu%20items

Hope you like this updated version of the code snippet. 

Thank you, and I will see you again in another useful blog post just like this one.

If this helped you, please share this with your colleagues, leave a comment below or just simply take a walk enjoying the nature around you, while building a better ‘you‘ and thus building a better planet.

9 thoughts on “Google Docs: How to Insert Date and Time (Macro)”

  1. This script prints time for GMT and date YYYY-MM-DD
    I changed the script to suit my timezone which is GMT + 10hrs (AEST) and date is DD-MM-YYYY
    I replaced all entries of “GMT” with “GMT+10” and all moved the dd MM and YYYY to suit my location
    Saved the script and inserted time.
    Worked perfectly
    Thanks heaps for a great utility!

    Reply
  2. I cannot get this to work. Have tried it on three different documents, and there’s another web page with the same code, and I get the same problem – no menu item appears after I save the script and refresh the document. I’ve tried on an existing document and blank document.
    Notes:
    1, “code.gs” appears at the top of the script, appears to be a name
    2. When I click File/Save and enter “Date-Time” as the name, I sometimes got a popup that said “Save Project” or something like that. This doesn’t appear once I save the file though. Saving it again and again, it just saves. But the “code.gs” still appears in the “tab” at the top of the file.
    3. Again, NO NEW MENU appears. It just doesn’t work.

    PS. I’m starting to think this whole project is an elaborate joke. Creating a script to enter the date and time, over and over for each document? It’s a lot easier to just type in the date and time.

    Reply
    • Hi, John. I have presented a video walk-through of these exact same steps above in the YouTube video. Have you watched that yet? It may help – just please follow along and it should work.

      Regards,
      Arun

      Reply
    • I did a lot of clicking around and got it to work.
      I pressed “deploy” then “test deployments”.
      I clicked on “select type” and chose “Add-On” and finally “done”.

      Then I was on the Apps Script and on the far left chose “executions”. I clicked on mine that I just created (because it was the only one created). Then I clicked on the word “refresh” in blue.

      Finally, I clicked back on my document and refreshed it and I saw utilities.

      Now, I don’t know how to change the code to make it Month, date, Year…

      In conclusion, I did get it to work. This was my first script, so I was pleased.

      Reply
  3. Hi and thank you for this. However, after doing everything you detailed, I go to enter the date and Google has me login to “Auto Date” as a third party app and then denies my access. Any suggestions?

    THANKS AGAIN!

    Reply

Leave a Comment

14 + 3 =