gettin records from today, yesterday, etc.
| From: | andy | Date: | Mon, 02 Sep 2002 14:32:58 +0000 |
| Subject: | gettin records from today, yesterday, etc. | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-21517@lists.php.net to get a copy of this message | ||
Hi there,
I am wondering how to get recors out of a mysql db from yesterday, last week
and last month. I did write a small php hack but this does not work
properly.
I did this:
###################################################
switch ($ts){
case 1: // today
$timestamp = substr($timestamp,0,8).'000000';
break;
case 2: // yesterday
$timestamp = (substr($timestamp,0,8)-1).'000000';
break;
case 3: // last week
$timestamp = (substr($timestamp,0,8)-7).'000000';
break;
};
$start_date = $timestamp;
$display_option = "AND p.timestamp > '$start_date'";
###################################################
But it leads to problems if I search for last week since I do a siple
subtraction of integer values and not of real days.
Maybe some of you guys has a better appoach?
Thanx,
Andy