How do I get the day of the month in javascript?

Javascript

Javascript Problem Overview


I need to get the day of the month from a Date object but it seems that the getDay() method returns the day of the week. Is there a function that returns the day of the month?

Javascript Solutions


Solution 1 - Javascript

Use date_object.getDate() to get the month day.

From the MDN docs link:

>"Returns the day of the month for the specified date according to local time."

Solution 2 - Javascript

Try getDate() instead. Confusing naming, but that's life...

Solution 3 - Javascript

var date = new Date().getDate();

From Mozilla Developer Network:

> Date.prototype.getDate() > The getDate() method returns the day of the month for the specified date according to local time.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getDate

Solution 4 - Javascript

const date = new Date();

const day = date.getDate();
const month = date.getMonth() + 1;
const year = date.getFullYear();

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionOleksandr IYView Question on Stackoverflow
Solution 1 - JavascriptI Hate LazyView Answer on Stackoverflow
Solution 2 - JavascriptMarc BView Answer on Stackoverflow
Solution 3 - JavascriptKevin BoucherView Answer on Stackoverflow
Solution 4 - JavascriptDiogo CapelaView Answer on Stackoverflow