[英]How to compare date today with date present in an SQL Server database?
I am executing a query where I am trying to compare the date in the database to the date today. 我正在执行一个查询,试图将数据库中的日期与今天的日期进行比较。
I am looking for the number of people that haven't left the company and for the ones where Exit Date is more than the current date. 我正在寻找尚未离开公司的人数以及退出日期超过当前日期的人数。
What I am trying to do is as follows: 我想做的事情如下:
SELECT Count(*)
FROM CompanySystemUsers
WHERE [Exit Date] IS NULL OR *To add code here*
[Exit Date] has a datatype of date in the table CompanySystemUsers [退出日期]在表CompanySystemUsers中具有日期的数据类型
In To add code here , I want to add the comparison statement where I can compare today's date to the [Exit Date] column values in the table 在此处要添加代码中 ,我想添加比较语句,在这里我可以将今天的日期与表中的[退出日期]列值进行比较
try this 尝试这个
select count(*) from CompanyStsystemUsers
where [Exit Date] is null or [Exit date] >= cast(getdate() as date)
what you need is getdate()
您需要的是
getdate()
Try This.. 尝试这个..
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.