Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

javascript

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?

like image 700
Oleksandr IY Avatar asked Oct 11 '12 17:10

Oleksandr IY


People also ask

How do you get the first working day of the month in JavaScript?

To get the first day of a month, use the Date() constructor to create a date object, passing it the year, month and 1 for the day as parameters. The Date object will contain the first day of the month.

How do I get the first day of my current month?

1. First day of current month: select DATEADD(mm, DATEDIFF(m,0,GETDATE()),0): in this we have taken out the difference between the months from 0 to current date and then add the difference in 0 this will return the first day of current month.

What is the keyword for extracting the day of the month?

The Date Object in JavaScript The Date object is created by using the new keyword, i.e. new Date() and provides a number of built-in methods for formatting and managing that data. Now, let's take a look at how to extract the day and month from this output, and get their names!


Video Answer


2 Answers

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."

like image 75
I Hate Lazy Avatar answered Oct 09 '22 13:10

I Hate Lazy


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

like image 27
Marc B Avatar answered Oct 09 '22 13:10

Marc B