'How can I search by datetime in sql?
In my Dateset, order_createdat is a datetime field with format of 'yyyy-mm-dd hh:mm:ss'.
I would like to search the values before 2021-02-10 15:30:00 based on this field. How should I write my conditions in the WHERE Clause?
Solution 1:[1]
This is not a complicated case. Just add where clause like this:
Where order_createdat = '2021-02-10 15:30:00'
If you want compare only date part; then
Where order_createdat = Cast('2021-02-10 15:30:00' as Date)
It can be even a Variable:
DECLARE @DateTime DATETIME = '2021-02-10 15:30:00'
Where order_createdat = @DateTime
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Meyssam Toluie |
