Mysql 16: Using DATETIME
Written by: maffelu , 2009-11-01 10:02:49
| id | entry | date |
|---|---|---|
| 1 | I am a happy camper | 2009-11-01 09:35:35 |
| 2 | I am a capped hampster | 2009-11-02 09:35:49 |
| 3 | I am a wrapped tramp | 2009-11-03 09:36:10 |
| 4 | I am a crappy camper | 2009-11-04 09:36:27 |
| 5 | I am a lappy santa | 2009-11-05 09:36:43 |
| 6 | I am a snappy tamper | 2009-11-06 09:37:03 |
SELECT date, entry
FROM entries
WHERE date >= '2009-11-01'
AND date <= '2009-11-03'
SELECT date, entry
FROM entries
WHERE DAY(date) >= 1
AND DAY(date) <= 3
| entry | date |
|---|---|
| I am a happy camper | 2009-11-01 09:35:35 |
| I am a capped hampster | 2009-11-02 09:35:49 |
| I am a wrapped tramp | 2009-11-03 09:36:10 |
SELECT DATE_ADD(date, INTERVAL 10 DAY), entry
FROM entries
WHERE DAY(date) = 1
| entry | date |
|---|---|
| I am a happy camper | 2009-11-11 09:35:35 |
SELECT DATE_SUB(date, INTERVAL 10 DAY), entry
FROM entries
WHERE DAY(date) = 1
| entry | date |
|---|---|
| I am a happy camper | 2009-10-22 09:35:35 |
SELECT DATEDIFF(date, '2009-10-01') as difference, date, entry
FROM entries
WHERE DAY(date) = 1
| difference | date | entry |
|---|---|---|
| 31 | 2009-10-22 09:35:35 | I am a happy camper |
There are no comments on this article.
If you have any question or just want to leave a message, just fill out the form below!
Your e-mail will not be visible in your post, it is for validation reasons only
Maffelu
Creator and admin of MorkaLork.com.
Started programming in HTML back when frames and tables was the way to design a page, moved on to Pascal/Delphi, PHP, javascript/jQuery, VB.NET/C#, Java and C++.
Currently studies .NET (in general) focusing on ASP.NET.