Reputation: 689
I Have a Table Name transactions
+-------+---------------------+--------+
| t_id | date | amount |
+-------+---------------------+--------+
| 10 | 2016-04-17 19:24:05 | 1800 |
| 12 | 2016-06-11 12:40:13 | 200 |
| 17 | 2016-04-13 14:42:04 | 100 |
| 19 | 2016-05-14 17:45:43 | 1 |
| 20 | 2016-08-15 19:45:54 | 999 |
| 21 | 2016-01-17 11:46:02 | 1500 |
| 41 | 2016-02-18 17:23:14 | 500 |
| 42 | 2016-07-19 13:26:14 | 500 |
| 43 | 2016-02-18 17:23:15 | 500 |
| 44 | 2016-02-18 17:23:16 | 500 |
| 45 | 2016-02-18 18:23:16 | 500 |
| 46 | 2016-02-18 17:23:16 | 500 |
| 47 | 2015-10-18 14:23:17 | 500 |
| 48 | 2015-11-18 17:23:17 | 500 |
| 49 | 2015-12-18 11:23:18 | 500 |
| 50 | 2015-05-18 11:25:54 | 1000 |
| 51 | 2015-09-18 12:26:22 | 3000 |
| 52 | 2015-05-18 13:48:59 | 10 |
| 53 | 2015-03-18 15:48:59 | 10 |
| 54 | 2015-01-18 17:49:13 | 5000 |
+-------+---------------------+--------+
I want to SELECT record with date
I Use
SELECT * FROM transactions WHERE date='2016-02-18';
I Also SELECT between 2 date And I Use
SELECT * FROM transactions WHERE date<'2016-02-18' AND date>'2016-02-01';
But Its Not Working.(I use php Mysql xampp) Can you help me understand the concepts?
Upvotes: 3
Views: 1265
Reputation: 16117
For the ist query you need to use DATE()
function becuase your column type is DATETIME
or TIMESTAMP
so you can handle it as:
SELECT * FROM transactions WHERE DATE(date) = '2016-02-18';
For second query you can simply add the TIME as:
SELECT * FROM transactions WHERE date > '2016-02-01 00:00:00' AND date < '2016-02-18 23:59:59';
Upvotes: 2
Reputation: 1390
use this
use % and like in your query . you will get all results in given date
SELECT * FROM transactions WHERE date like '2016-02-18%';
Upvotes: 1
Reputation: 3756
you should use BETWEEN ... AND ...
SELECT * FROM transactions WHERE `date` BETWEEN '2016-02-01' AND '2016-02-18';
Upvotes: 0
Reputation: 1191
Is it a mysql DB ?
If it is than use DATE
function :
SELECT * FROM transactions WHERE DATE(date)='2016-02-18';
OR
SELECT * FROM transactions WHERE date BETWEEN '2016-02-18' AND '2016-02-01';
Upvotes: 1