doing the math
Posted 26 July 2006 - 04:26 AM
$date = "20060725202938";
$last_30min = $date - 1440;
Posted 26 July 2006 - 04:48 AM
How did that number get into your database? What is the field type?
Posted 26 July 2006 - 04:53 AM
so how do you suggest i convert my database to unix timestamp instead of this format then i guess?
Posted 26 July 2006 - 05:10 AM
"normal" date/time string by doing:
<?php $dt = "20060725202938"; $new_dt = substr($dt,0,4) . '-' . substr($dt,4,2) . '-' . substr($dt,6,2) . ' ' . substr($dt,8,2) . ':' . substr($dt,10,2) . ':' . substr($dt,12,2); ?>The the date/time string for 30 minutes earlier can be gotten with:
<?php $last_30min = date('F j, Y G:i',strtotime('-30 minutes ' . $new_dt)); ?>
Posted 26 July 2006 - 05:33 AM
Posted 26 July 2006 - 10:57 AM
On select, always use UNIX_TIMESTAMP, for easy use in php.
SELECT UNIX_TIMESTAMP(`somedatetimefield`) AS somedatetimefield
to for example select all id's of entries that where modified in the past 30 min:
SELECT id FROM somtable WHERE TIMEDIFF(NOW(),timestampfield)<MAKETIME(0,30,0)
Converting the columns to unix timestamps is not required, nor handy. You won't be able to use mysql's timestamp type columns, you'd have to use php's time() and insert/modify it every time you alter a table.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users