Date returning wrong month

I’m running a Discord bot and the timestamp on some commands returns the wrong month.

with the code

var day   = d.getDate();
var y     = d.getFullYear();
var month = d.getMonth(); 
dmy = day + "/" + month + "/" + y // DD/MM/YY
console.log(dmy)

it logs 1/3/2020
today is April 1st, 1/4/2020

I’m running on node 12

I’m not sure what could be wrong, any ideas?

thank you in advance

they start counting from zero, and January is month 0 \:

duh, shouldve looked into it more

thx

here is a simple fix :smiley::
var month = d.getMonth() + 1;

thats what I did and it’s working fine now :slight_smile:

1 Like

Oh my God, I never noticed that and that means that my database is ruined!

2 Likes

OOOF!

Yea, easy to mess up when it comes to the date module.

Looks like this has been resolved, that’s great! I’m moving the topic to the coding help category just to keep things organized.