开发者

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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜