RE: [PHP] Making several variables into 1 variable

From: Date: Tue, 28 Jul 2009 13:46:07 +0000
Subject: RE: [PHP] Making several variables into 1 variable
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-295925@lists.php.net to get a copy of this message
On Tue, 2009-07-28 at 09:41 -0400, Bob McConnell wrote: > From: Ashley Sheridan > > On Tue, 2009-07-28 at 09:32 -0400, Miller, Terion wrote: > >> I need to take this: > >> > >> $pastDays = strtotime("-30 days"); > >> > >> > >> > >> $past_day = date("d", $pastDays); > >> > >> $past_month = date("m", $pastDays); > >> > >> $past_year =date("y", $pastDays); > >> > >> > >> And make it into one var to compare to a db field that is formatted > like > >> 00/00/00 > >> > >> > > Erm, why don't you do this: > > > > $pastDays = strtotime("-30 days"); > > $date = date("d/m/y", $pastDays); > > > > The date() function allows you to mix in all sorts of characters into > > the output it formats, and you can escape characters that have special > > meaning with a slash '\' character. > > The problem with that is if that field is a string, and not formatted as > YY/MM/DD, then a simple compare won't work in January. You have to break > it down into the three components and compare each one in turn. > > Bob McConnell > I assumed that the date field in MySQL was a date or datetime type. It would be a little silly to store dates in the database any other way? Thanks, Ash http://www.ashleysheridan.co.uk

« previous php.general (#295925) next »