开发者

mysql with the date function

开发者 https://www.devze.com 2023-01-10 03:27 出处:网络
I have a mysql table containing a field name dtt_date and have values like 08/04/2010 22:15:00. I want to display all the records with in this mont开发者_StackOverflow社区h (08, august), How to write

I have a mysql table containing a field name dtt_date and have values like 08/04/2010 22:15:00. I want to display all the records with in this mont开发者_StackOverflow社区h (08, august), How to write a mysql query in my php page to display these record. Does any one know this?

Please help me?


  SELECT * FROM table WHERE dtt_date>='2010-08-01' AND dtt_date<='2010-08-31';

In PHP:

 $q = "SELECT * FROM table WHERE dtt_date>='2010-08-01' AND dtt_date<='2010-08-31'";
 $res = mysql_query($q);
 while($row = mysql_fetch_assoc($res))
   var_dump($row);
 mysql_free_results($res);


Untested, I'm sure there are easier methods to this. Not sure if your date format will be handeled by MySQL

SELECT * FROM table WHERE MONTH(DATE_FORMAT(date,'%Y-%m-%d')) = 8


You can try this one method

SELECT * FROM table WHERE month(dtt_date)='08' AND year=(dtt_date)='2010';


You should change the date format in the table to be '2010-08-04 22:15:00', then you could run this query:

SELECT DATE_FORMAT(dtt_date, '%D %M %Y') as date FROM myTable

From there you would get something of this as a result, and then you can experiment with the date formatting.

+-----------------+
| date            |
+-----------------+
| 4th August 2010 | 
+-----------------+
0

精彩评论

暂无评论...
验证码 换一张
取 消