Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

davy_yg's avatar
Level 27

get month from date

How to get month from date?

var valtgl = $("#val-tgl").val();
            
    //var month = valtgl.getMonth()      

this is the value of valtgl:

2020-11-14

I want to get month how?

0 likes
2 replies
Sirik's avatar
Sirik
Best Answer
Level 11

You go a string not a date object

var valtgl = $("#val-tgl").val();
var date = new Date(valtgl);
var month = date.getMonth();
cuwa's avatar

Another basic question you asked that you could easily have found the answer for yourself. Let me help you out with that: http://lmgtfy.com/?q=javascript+get+month+from+date

You're never going to learn anything about programming if you always have other people solve your problems for you.

2 likes

Please or to participate in this conversation.