I need to select all records for the preceding 7 days from a mysql table with timestamp
Am using
$sql1 = "SELECT * FROM $table WHERE UNIX_TIMESTAMP(timestamp) >= '$start' && UNIX_TIMESTAMP(timestamp) <= '$end' ";
How do I calculate what the value of $end is? when $end is 7 days prior to today.
im not 100% sure how UNIX_TIMESTAMP() is handled by mysql - but i assume, that it is calculated in seconds past 01-01-1970.
if this is the case, then it should be like this:
$end = time() - (60 * 60 * 24 * 7); //secs * mins * hours * days
Or
strtotime('7 days ago')
Or use MySQL's own date and time functions in the query. Surely it offers functions for working with its own data types.
Thanks, got it doing what I want.