Skip to main content
Solved

Scripting automation incorrect month from date object

  • September 19, 2022
  • 3 replies
  • 0 views

Hi all! I’m working on an automation script which needs to get the current date so that it can be formatted for a URL. However, calling the .getMonth() function on a date object returns an incorrect month. I can of course correct for this by adding 1 to each month but would prefer not to.

I’ve created a new script which creates a date and logs the resulting month to demonstrate my issue:

The code:

The resulting console logs:

Has anyone encountered this issue before? Thanks!

Best answer by Vivid-Squid

Hi @Sam_Richter,
I believe that getMonth() is zero based value, so January is 0.

View original
Did this topic help you find an answer to your question?

3 replies

  • Inspiring
  • 532 replies
  • Answer
  • September 19, 2022

Hi @Sam_Richter,
I believe that getMonth() is zero based value, so January is 0.


  • Author
  • New Participant
  • 1 reply
  • September 19, 2022
Vivid-Squid wrote:

Hi @Sam_Richter,
I believe that getMonth() is zero based value, so January is 0.


Thanks @Vivid-Squid I’m going to look more closely at the JS documentation in the future.


  • Inspiring
  • 3264 replies
  • September 19, 2022

This is not an Airtable behaviour; it is how javascript dates work. This is a flaw inherited from Java way back before you were born. :winking_face:

stackoverflow.com/questions/344380/…


Reply