Help

Scripting automation incorrect month from date object

Topic Labels: Automations
Solved
Jump to Solution
1102 3
cancel
Showing results for 
Search instead for 
Did you mean: 
Sam_Richter
4 - Data Explorer
4 - Data Explorer

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:
Code Snippet

The resulting console logs:
Console log

Has anyone encountered this issue before? Thanks!

1 Solution

Accepted Solutions
Vivid-Squid
11 - Venus
11 - Venus

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

See Solution in Thread

3 Replies 3
Vivid-Squid
11 - Venus
11 - Venus

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.

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/…