Re: Date Arithmetic

From: Date: Tue, 01 Oct 2002 21:38:49 +0000
Subject: Re: Date Arithmetic
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-118439@lists.php.net to get a copy of this message
Sascha Braun wrote: > > I have a small but hard to solve problem to solve. > > Wrote a Select Query for my webpage. > > The query should select all values which where > written into the DB the last seven Days. > > I thought everything was working fine, but now > the month has changed and everything went > wrong. > > My Select Query is not able to go into the Last > month in calculation. > > I don't really know how to manage this problem. > > Please Help > > Here is the Query: > > $Query = "SELECT * FROM bild_db WHERE datum > '".date('Y') . > '-' . date('m') . '-' . (date('d') - > $_REQUEST['days']) . ' 00:00:00'."'"; > > Another code snipped: > > <? echo date('Y') . '-' . date('m') . '-' . > (date('d') - 7); ?> > > The code will work fine as long you are not at the beginning > of the month. Or in the first six days. There's a few ways to do this. The following may work (I didn't test). $query = "SELECT " ." * " ."FROM " ." bild_db " ."WHERE " ." datum > DATE_SUB( NOW(), INTERVAL 1 MONTH ) "; Cheers, Rob. -- .-----------------. | Robert Cummings | :-----------------`----------------------------. | Webdeployer - Chief PHP and Java Programmer | :----------------------------------------------: | Mail : mailto:robert.cummings@webmotion.com | | Phone : (613) 731-4046 x.109 | :----------------------------------------------: | Website : http://www.webmotion.com | | Fax : (613) 260-9545 | `----------------------------------------------'

« previous php.general (#118439) next »