I'm trying get the results where it only displays OrderDates before the LAST day of the CURRENT month. I'm guessing it would be like this...
SELECT OrderDate FROM Orders WHERE OrderDate < (code for first day of the next month?)
For getting the first day of next month based on given date in Excel, the following formula can help you. Select a blank cell, enter formula =DATE(YEAR(A2),MONTH(A2)+1,1) into the Formula Bar and then press the Enter key. Then use the Fill Handle to get the rest dates. See screenshot.
January is the first month of the year in the Julian and Gregorian calendars and the first of seven months to have a length of 31 days. The first day of the month is known as New Year's Day.
Use EOMONTH Get the Beginning of the Month Date You can also use EOMONTH to get the first day of the month. EOMONTH takes a date and helps you get the last date of a month, and you can add 1 into it to get the first day of the month.
To get the same date next month from a given date, you can use the EDATE function. EDATE can get the "same date" in the future or past, based on the number of months supplied. When 1 is given for months, EDATE gets the same date next month.
First day of next month:
sql-server 2012+
DATEADD(d, 1, EOMONTH(current_timestamp))
sql-server 2008 and older:
DATEADD(m, DATEDIFF(m, -1, current_timestamp), 0)
Your question is somewhat ambiguous, but this will give you '(code for the first day of the month)'
SELECT OrderDate FROM Orders WHERE ORDERDATE < DATEADD(month, DATEDIFF(month, 0, GETDATE()), 0)
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