Re: Formating MySQL dates

From: Date: Tue, 13 Jun 2000 14:44:15 +0000
Subject: Re: Formating MySQL dates
Groups: php.general 
Request: Send a blank email to php-general+get-1716@lists.php.net to get a copy of this message
I created the following function that I use a lot for formating dates coming from databases. It's simple to use: format_date("2000-06-01 14:05:12") OR format_date("2000-06-01 14:05:12","d/m/Y") /*******/ function format_date($the_date, $format = "n-j-Y") { if ( ereg( "([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $the_date, $regs ) ) { return date($format, mktime($regs[4],$regs[5],$regs[6],$regs[2],$regs[3],$regs[1])); } else { return "Invalid date format: $the_date"; } } -- Matthew Leverton - matthew@aeroinc.net - http://www.allegro.cc -----Original Message----- From: Phillip S. Baker <phillip@wordsandimages.com> To: php-general@lists.php.net <php-general@lists.php.net> Date: Tuesday, June 13, 2000 8:43 AM Subject: [PHP-GENERAL] Formating MySQL dates >Hey Gents, > >How do I take the standard YYYY-MM-DD date entry in MySQl and format >it so information pulled from MySQL is displayed differently when >actually put on the web? > >Thanks >-- > >Phillip S. Baker > >phillip@wordsandimages.com >Words & Images, Inc. >1535 Seabright Avenue, Suite 100, Santa Cruz, CA 95062 >Direct Line (831) 420-2641 / Fax (831) 458-0808 > >-- >PHP General Mailing List (http://www.php.net/) >To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net >For additional commands, e-mail: php-general-help@lists.php.net >To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#1716) next »