Re: Formatting a string to a date...need coffee...

From: Date: Sat, 01 Jul 2000 20:47:05 +0000
Subject: Re: Formatting a string to a date...need coffee...
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-4295@lists.php.net to get a copy of this message
On Sat, 1 Jul 2000, Digital Hit Entertainment wrote: > I'm putting this down to a distinct lack of coffee in my system. I've > been trying to format a date from MS SQL Server 7 to a better format. > Read the manual but it's one of those "answer's right under your nose" > moments. I don't need the time portion of the date, so I used $date = > substr ("$date",0,10); to remove the time portion of the SQL7 date and > leave 2000-05-22. What do I need to do to turn that into May 5, 2000. > > Many thanks. The loud noise you'll hear will be me banging my head on > the desk when I get the answer. ;-) First, let me begin by handing you a pillow to place on your desk. :) Having gotten that out of the way, if you have a string in YYYY-MM-DD, explode it to an array with year, month, and day components, and use them with date() and mktime(). // So the first array element is year, second is month, third is day $datearr = explode('-',$datestring); // mktime takes its args as hour,min,sec,month,day,year echo date('M d, Y',mktime(0,0,0,$datearr[1],$datearr[2],$datearr[0])); Matt

« previous php.general (#4295) next »