Share via

date function in Sql

Jonathan Brotto 420 Reputation points
24 Sept 2024, 6:11 pm

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.
14,320 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.
111 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,676 questions
{count} votes

1 answer

Sort by: Newest
  1. Viorel 119K Reputation points
    24 Sept 2024, 6:25 pm

    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.