请帮助,我正试图在本月展示我的数据。
这是我现在的查询:
select
IdEnt,
convert(varchar(20),InputDate,103) as 'InputDate',
userID,
Nominal,
TypeCost,
convert(varchar(20),EntDate,103) as 'EntDate',
EntParty,
Premi,
Div,
RemarksAgent,
RemarksFinance
from
entReq
where
userID = $_SESSION[userID]
order by
InputDate desc;
答案 0 :(得分:2)
以下是使用EOMONTH
SELECT ident,
CONVERT(VARCHAR(20), inputdate, 103) AS 'InputDate',
userid,
nominal,
typecost,
CONVERT(VARCHAR(20), entdate, 103) AS 'EntDate',
entparty,
premi,
div,
remarksagent,
remarksfinance
FROM entreq
WHERE userid = $_SESSION[userID]
AND inputdate >= Dateadd(dd, 1, EOMONTH(Getdate(), -1))
AND inputdate < Dateadd(dd, 1, EOMONTH(Getdate()))
ORDER BY inputdate DESC;
对于旧版本:
每月的第一天:DATEADD(mm, DATEDIFF(mm, 0, GETDATE()), 0)
每月最后一天:DATEADD (dd, -1, DATEADD(mm, DATEDIFF(mm, 0, GETDATE()) + 1, 0))