Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Compare a date variable with today's date

Author  Topic 

cullyK
Starting Member

5 Posts

Posted - 2007-02-06 : 12:40:06
ok so I am guessing you use the datediff function but not sure how to get the output i actually want.

I have a variable @mydate I want to see if it is before or on todays date.

Is it something like
if not DATEDIFF(day,getDate(),@mydate) > 1
begin
--then @mydate is a date before today
End

having a hard time testing this, thanks

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-02-06 : 13:12:29
if @mydate < getdate()
select 'yesterday or before'
else
select 'the future!'

if datediff(day, @mydate, getdate())) > 0
select 'yesterday or before'
else
select 'the future!'


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

cullyK
Starting Member

5 Posts

Posted - 2007-02-07 : 04:05:20
thank you sir
Go to Top of Page
   

- Advertisement -