- DATE - format
YYYY-MM-DD
- DATETIME -
format: YYYY-MM-DD HH:MM:SS
- TIMESTAMP -
format: YYYY-MM-DD HH:MM:SS
- YEAR - format
YYYY or YY
- DATE - format
YYYY-MM-DD
- DATETIME -
format: YYYY-MM-DD HH:MM:SS
- SMALLDATETIME
- format: YYYY-MM-DD HH:MM:SS
- TIMESTAMP -
format: a unique number
SQL Working with Dates
Assume we have the following "Orders" table:
OrderId
|
ProductName
|
OrderDate
|
1
|
Geitost
|
2008-11-11
|
2
|
Camembert Pierrot
|
2008-11-09
|
3
|
Mozzarella di Giovanni
|
2008-11-11
|
4
|
Mascarpone Fabioli
|
2008-10-29
|
Now we want to select the records with an OrderDate of "2008-11-11" from the table above.
We use the following SELECT statement:
SELECT * FROM Orders WHERE
OrderDate='2008-11-11'
|
The result-set will look like this:
OrderId
|
ProductName
|
OrderDate
|
1
|
Geitost
|
2008-11-11
|
3
|
Mozzarella di Giovanni
|
2008-11-11
|
Now, assume that the "Orders" table looks like this (notice the time component in the "OrderDate" column):
OrderId
|
ProductName
|
OrderDate
|
1
|
Geitost
|
2008-11-11 13:23:44
|
2
|
Camembert Pierrot
|
2008-11-09 15:45:21
|
3
|
Mozzarella di Giovanni
|
2008-11-11 11:12:01
|
4
|
Mascarpone Fabioli
|
2008-10-29 14:56:59
|
If we use the same SELECT statement as above:
SELECT * FROM Orders WHERE
OrderDate='2008-11-11'
|
0 comments:
Post a Comment