Comparing Unix Timestamps |
[eluser]PHP Creative[/eluser]
Hi there I was wondering it is possible to compare Unix Timestamps. Basically I have table with date_added column and I would like to only select the records entered this month. This is possible? Thanks a million
[eluser]danmontgomery[/eluser]
Code: SELECT * FROM my_table WHERE DATE_FORMAT(FROM_UNIXTIME(date_added), '%c') = '2' Or, you can create a unix_timestamp in PHP and do a direct comparison... You'll want to watch out for timezone compensation though. Code: $start_timestamp = strtotime(date("F 1, Y")); [edit] For past months I guess you would also want to limit the top end of the search
[eluser]PHP Creative[/eluser]
Sorry for dragging this up again. How would I go about adding or subtractng days/months/years to the timestamp? I have the tried the following with no luck Code: strtotime(date("F -1 Month, Y")); Thanks a million.
[eluser]danmontgomery[/eluser]
In PHP, strtotime(): Code: date("F, Y", strtotime("-1 month")); In MySQL, DATE_SUB() or DATE_ADD() Code: SELECT DATE_SUB(NOW(), INTERVAL 1 MONTH); |
Welcome Guest, Not a member yet? Register Sign In |