Comparing results with today's date?

前端 未结 10 1704
情深已故
情深已故 2020-12-08 09:15

Is there a way to use the Now() function in SQL to select values with today\'s date?

I was under the impression Now() would contain the ti

10条回答
  •  轮回少年
    2020-12-08 09:47

    There is no native Now() function in SQL Server so you should use:

    select GETDATE() --2012-05-01 10:14:13.403
    

    you can get day, month and year separately by doing:

    select DAY(getdate())  --1
    select month(getdate())  --5
    select year(getdate()) --2012
    

    if you are on sql server 2008, there is the DATE date time which has only the date part, not the time:

    select cast (GETDATE() as DATE) --2012-05-01
    

提交回复
热议问题