How do I query for all dates greater than a certain date in SQL Server?

I’m trying:

SELECT * 
FROM dbo.March2010 A
WHERE A.Date >= 2010-04-01;

A.Date looks like: 2010-03-04 00:00:00.000

  • stored procedure returns just one row of multiple rows
  • Why is this query slow the first time after I start the service?
  • How to determine the number of days in a month in SQL Server?
  • Re-use aliased field in SQL SELECT statement
  • Querying a linked sql server
  • Inserting values into a table based on column values of another table
  • However, this is not working. Can anyone provide a reference for why?

  • How significant is the performance difference when joining on nvarchar versus on int
  • Why can't I use alias in a count(*) “column” and reference it in a having clause?
  • Multiple FULL OUTER JOIN on multiple tables
  • How to display all record from left table using left join in my case using SQL Server?
  • SQL Creating UDF Computed columns
  • For SQL select returning more than 1 value, how are they sorted when Id is GUID?
  • 4 Solutions collect form web for “How do I query for all dates greater than a certain date in SQL Server?”

    select *  
    from dbo.March2010 A 
    where A.Date >= Convert(datetime, '2010-04-01' )
    

    In your query, 2010-4-01 is treated as a mathematical expression, so in essence it read

    select *  
    from dbo.March2010 A 
    where A.Date >= 2005; 
    

    (2010 minus 4 minus 1 is 2005
    Converting it to a proper datetime, and using single quotes will fix this issue.)

    Technically, the parser might allow you to get away with

    select *  
    from dbo.March2010 A 
    where A.Date >= '2010-04-01'
    

    it will do the conversion for you, but in my opinion it is less readable than explicitly converting to a DateTime for the maintenance programmer that will come after you.

    Try enclosing your date into a character string.

     select * 
     from dbo.March2010 A
     where A.Date >= '2010-04-01';
    

    We can use like below as well

    SELECT * 
    FROM dbo.March2010 A
    WHERE CAST(A.Date AS Date) >= '2017-03-22';
    
    SELECT * 
        FROM dbo.March2010 A
        WHERE CAST(A.Date AS Datetime) >= '2017-03-22 06:49:53.840';
    
    DateTime start1 = DateTime.Parse(txtDate.Text);
    
    SELECT * 
    FROM dbo.March2010 A
    WHERE A.Date >= start1;
    

    First convert TexBox into the Datetime then….use that variable into the Query

    MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.