Date Differences | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

Date Differences

Hi I want to compare two dates like
date >(select Getdate()) Is it possible?

Basically Yes. Just do the comparison like …date > GETDATE() without the extra SELECT. —
Frank Kalis
Microsoft SQL Server MVP
http://www.insidesql.de
Heute schon gebloggt?http://www.insidesql.de/blogs

quote:Originally posted by rajkolli_2000 Be carefull though. As far as i know Getdate() gives back the current Date AND Time.
If date is of the same type en is of today at 8:00 in the evening, then the test would indicate that date is greater than GetDate() although for us the dates would seem equal. If you are as paranoid as i am you could test using the year, month and day as in: ((year(date) >= Year(Getdate())) And (Month(date) >= Month(Getdate())) And (Day(date) > Day(Getdate())))
Just my two cents Kees Hi I want to compare two dates like
date >(select Getdate()) Is it possible?

>> ((year(date) >= Year(Getdate())) And (Month(date) >= Month(Getdate())) And (Day(date) > Day(Getdate()))) This will not be very efficient as it may result in a SQL Server performing a scan
If you need to ignore the time, do this instead date > dateadd(day, 0, datediff(day, 0, getdate())) ——
> KH <
http://www.sql-server-performance.com/fk_datetime.asp —
Frank Kalis
Microsoft SQL Server MVP
http://www.insidesql.de
Heute schon gebloggt?http://www.insidesql.de/blogs

>>date > dateadd(day, 0, datediff(day, 0, getdate())) or date > dateadd(day, datediff(day, 0, getdate()),0)
Madhivanan Failing to plan is Planning to fail
]]>