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?
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.
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.
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!
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."
Try getDate() instead. Confusing naming, but that's life...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With