Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
in SQL by (20.3k points)

I am looking for a good SQL Statement to select all rows from the previous day from one table. The table holds one datetime column. I am using SQL Server 2005.

1 Answer

0 votes
by (40.7k points)

Use this code to get today no time:

SELECT dateadd(day,datediff(day,0,GETDATE()),0)

To get yesterday no time, use this query:

SELECT dateadd(day,datediff(day,1,GETDATE()),0)

Query for all of rows from only yesterday try this:



    from yourTable

    WHERE YourDate >= dateadd(day,datediff(day,1,GETDATE()),0)

        AND YourDate < dateadd(day,datediff(day,0,GETDATE()),0)

Related questions

Browse Categories