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 2000 Forums
 SQL Server Development (2000)
 Date Compare

Author  Topic 

BaldEagle
Starting Member

23 Posts

Posted - 2002-04-04 : 23:56:14
I always had a problem getting the date that matches with a date in the database. I have a database table with a column that contains the date/time. How can i write an SQL Statement to match all those records that has a date which is 1 day before today's date? Anyone can help me? Thanks :)

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2002-04-05 : 00:12:13
Hi

You can use the DateDiff function for this. In your case



SELECT * FROM Table
WHERE DateDiff(d, YourDateField, GetDate()) = 1



Hope that helps

Damian
Go to Top of Page

BaldEagle
Starting Member

23 Posts

Posted - 2002-04-05 : 00:19:16
hey i works, i do not know i can do itin this way. Thanks man !! :)

Go to Top of Page

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2002-04-05 : 00:23:29
No worries. Also, if you wanted to match today, you could just change the number to 0

Damian
Go to Top of Page
   

- Advertisement -