Re: Date format

From: Date: Wed, 19 Jul 2000 19:48:20 +0000
Subject: Re: Date format
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-1301@lists.php.net to get a copy of this message
Vojtech Dvorak pressed the little lettered thingies in this order... > I am using ODBC to get a dates from my MS Access database, > but problem comes when I need change format of dates I get.. > What I get is: "2000-04-12 14:06:09" > what I need is only: "12-04-2000" > > Do someone know how should I make it? > Thanks > Vojtech > I'm not sure if the others answered this, but this is a more consistent way to get the proper date: $startdate="2000-04-12 14:06:09"; $split=explode(" ",$startdate); $split2=explode("-",$split[0]); $showdate=date("m-d-Y", mktime(0,0,0,$split2[2],$split2[1],$split2[0])); echo $showdate; I prefer to use split() because substr() will not give you consistent results if the exact number of characters in the beginning date ever changes (like the month is "1" in January instead of "01"). Using date() and mktime() also allow you to rearrange the output date to look better if you desire to do so in the future. For exaple, if you wanted the output to read "Monday December 4th, 2000" all that you need to do is change the "m-d-Y" above to "l F jS, Y" In short, you'll leave yourself with much more flexible output in the future. Check out: http://www.php.net/manual/function.date.php and: http://www.php.net/manual/function.mktime.php for more information. Christopher Ostmo a.k.a. support@rosenet.net Rosenet, Inc. For a good time, http://modems.rosenet.net/mysql/

« previous php.db (#1301) next »