下个月的第一天

时间:2022-10-16 12:29:42

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?)

5 个解决方案

#1


42  

First day of next month:

下个月的第一天:

sql-server 2012+

sql server 2012 +

DATEADD(d, 1, EOMONTH(current_timestamp))

sql-server 2008 and older:

sql server 2008岁及以上:

DATEADD(m, DATEDIFF(m, -1, current_timestamp), 0)

#2


2  

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)

#3


2  

This one:

这一个:

DATE_FORMAT(NOW()+interval 1 month,'%Y-%m-01 00:00:00')

DATE_FORMAT(现在()+间隔1个月,Y ' % - % m-01就是”)

#4


1  

Try this

试试这个

SELECT OrderDate
FROM Orders 
WHERE ORDERDATE < DATEADD(dd,-(DAY(DATEADD(mm,1,getdate()))-1),DATEADD(mm,1,getdate()))

Take a look at here

看看这里

#5


1  

SELECT DATEADD(month, DATEDIFF(month, 0, getdate())+1, 0) AS StartOfMonth

#1


42  

First day of next month:

下个月的第一天:

sql-server 2012+

sql server 2012 +

DATEADD(d, 1, EOMONTH(current_timestamp))

sql-server 2008 and older:

sql server 2008岁及以上:

DATEADD(m, DATEDIFF(m, -1, current_timestamp), 0)

#2


2  

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)

#3


2  

This one:

这一个:

DATE_FORMAT(NOW()+interval 1 month,'%Y-%m-01 00:00:00')

DATE_FORMAT(现在()+间隔1个月,Y ' % - % m-01就是”)

#4


1  

Try this

试试这个

SELECT OrderDate
FROM Orders 
WHERE ORDERDATE < DATEADD(dd,-(DAY(DATEADD(mm,1,getdate()))-1),DATEADD(mm,1,getdate()))

Take a look at here

看看这里

#5


1  

SELECT DATEADD(month, DATEDIFF(month, 0, getdate())+1, 0) AS StartOfMonth