Sql Query needed
im storing date in mysql database with timestamp i开发者_StackOverflow社区n (int) type column.
but how can i get this ( CURRENT ) month current rows only?
What should be the sql query to fetch desired data?
Calculate the timestamp of the first and last secondof the month and use sqls BETWEEN
Add the year as well and you can use the date functions:
SELECT * FROM table WHERE YEAR(FROM_UNIXTIME(timestamp_field)) = YEAR(NOW()) AND MONTH(FROM_UNIXTIME(timestamp_field)) = MONTH(NOW())
$begin = strtotime(date('m/01/Y'));
$end = strtotime(date('m/t/Y'));
$sql = "SELECT * FROM table WHERE date >= $begin AND date <= $end"
This is probably the easiest and fastest solution. Using a SQL function like FROM_UNIXTIME()
can work, but it can lead to performance issues down the road.
精彩评论