Querying By Date
We are so frequently required to create date based queries, eg how many orders last week, last month, how many orders between two dates. It is necessary to avoid the trap of treating date as a number, instead convert the date into a handy unit such as days
# select all records from today
select * from tbl_orders where TO_DAYS(NOW()) = TO_DAYS(dtmdevdate);
# select all records from last three days
select * from tbl_orders where (TO_DAYS(NOW())-3) > TO_DAYS(orderdate);
MySQL provides a whole range of date functions become familiar with them here
http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html
# select all records from today
select * from tbl_orders where TO_DAYS(NOW()) = TO_DAYS(dtmdevdate);
# select all records from last three days
select * from tbl_orders where (TO_DAYS(NOW())-3) > TO_DAYS(orderdate);
MySQL provides a whole range of date functions become familiar with them here
http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html
Labels: date functions

0 Comments:
Post a Comment
<< Home