Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

First day of the next month

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?) 
like image 874
jaramore Avatar asked Mar 25 '14 01:03

jaramore


People also ask

How do you find the 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.

What is the first day month?

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.

How do you get the first day of a month in Excel?

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.

What is the formula for next month in Excel?

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.


2 Answers

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) 
like image 97
t-clausen.dk Avatar answered Sep 21 '22 03:09

t-clausen.dk


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) 
like image 32
E.J. Brennan Avatar answered Sep 24 '22 03:09

E.J. Brennan