Skip to content
Advertisement

Trying to get first date of current month in html date picker

Hi I am trying to get first date of current month in HTML date picker.

JavaScript

I get today date in id=”tdate like this given below but starting date of current month not able to get as I get current date.

JavaScript

Advertisement

Answer

date input fields must be in YYYY-MM-DD format. Your code:

JavaScript

Will give back a string, e.g. Tue Sep 01 2020 00:00:00 GMT-0400 (Eastern Daylight Time), which is not what you want.

You can combine a couple of existing StackOverflow answers to accomplish what you want:

JavaScript

Assuming fdate should be the first of the month and tdate should be today’s date:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement