Re: gettin records from today, yesterday, etc.

From: Date: Mon, 02 Sep 2002 16:46:11 +0000
Subject: Re: gettin records from today, yesterday, etc.
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-21520@lists.php.net to get a copy of this message
Hi, It would better and far easier to use PHP's date functions, specifically getdate() and date(). Check out the documentation here: http://www.php.net/manual/en/function.getdate.php HTH, Jed On the threshold of genius, andy wrote: > 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 > >

« previous php.db (#21520) next »