date function in Sql

Jonathan Brotto 420 Reputation points
2024-09-24T18:11:46.69+00:00

I have a timestamp where I want to query only based on the date and exclude time.

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,799 questions
SQL Server Transact-SQL
SQL Server Transact-SQL
SQL Server: A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.Transact-SQL: A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
97 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,637 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Viorel 117.3K Reputation points
    2024-09-24T18:25:00.93+00:00

    Try the “cast-as-date”, for example:

    select *
    from MyTable
    where cast(column1 as date) = '2024-09-24'
    

    where column1 is a datetime value.

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.