RE: [PHP] Problem with Date Format

From: Date: Fri, 05 Jan 2001 14:17:32 +0000
Subject: RE: [PHP] Problem with Date Format
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-32880@lists.php.net to get a copy of this message
> -----Original Message----- > From: Seth Northrop [mailto:seth@calculon.northrops.com] > Sent: Friday, January 05, 2001 2:31 AM > To: davey sonya > Cc: php-general@lists.php.net > Subject: Re: [PHP] Problem with Date Format > > > > I need to retrieve a date which is in the format > > mm/dd/yy from my database and add 1 month to this > > date. I want to display this date as for eg 20 NOVEMBER > > 2000. > > If I'm understanding you something like this should work (untested and > from the hip). > > # set your DB date to $date then... > > # explode the date mm/dd/yy > $junk = explode("/",$date); > > # increment month > $month = $junk[0]+1; > > # Check for year roll over > if ($month == 13) > { > # set to first month > $month = 1; > > # roll year up one > $junk[2] = $junk[2]+1; > } In the interest of creating nice, compact code...the check for year rollover isn't actually necessary, since mktime() (called in the next line) will handle that internally by itself. > # Build new date format > $newdate = date("d F Y",mktime(0,0,0,$month,$junk[1],$junk[2])); --- Mark Roedel | "The most valuable function performed by Systems Programmer | the federal government is entertainment" LeTourneau University | Longview, Texas, USA | -- Dave Barry

« previous php.general (#32880) next »