Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP Databases
|
PHP Databases Using PHP in conjunction with databases. PHP questions not specific to databases should be directed to one of the other PHP forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 28th, 2003, 02:28 PM
Registered User
 
Join Date: Aug 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default date mysql to php display

HI, hope someone can help, I have just done my forst data base, now obviously the date in mysql is yyyy mm dd but when my users see it on the web interface I want them to see dd mm yy - how do I do this, have tried various sql commands and php but still displays incorrectly.

Thanks in advance

Ya man!!!
 
Old August 28th, 2003, 03:23 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You can either format the date in your MySQL query or with PHP.

In MySQL, you'll need the DATE_FORMAT() function.
  http://www.mysql.com/doc/en/Date_and...functions.html

SELECT DATE_FORMAT(date_col, '%d %m %y')
  FROM table_name

You can do it in PHP using regular expressions. Take a look at preg_replace()
  http://www.php.net/preg_replace

Also, you can convert the MySQL date to a unix timestamp, and then convert that timestamp to a date format of your choosing. PHP's date() function is similar to MySQL's DATE_FORMAT().
  http://www.php.net/strtotime
  http://www.php.net/date

date('d m y', strtotime($mysql_date));



Take care,

Nik
http://www.bigaction.org/
 
Old August 29th, 2003, 02:10 AM
Registered User
 
Join Date: Aug 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

:D:D

Many thanks Nik I will look at this today, have been wrestling with this for 2 days, appreciate your help.

G

Ya man!!!
 
Old August 30th, 2003, 06:39 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Did it work?

Take care,

Nik
http://www.bigaction.org/
 
Old September 1st, 2003, 08:13 AM
Registered User
 
Join Date: Aug 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default


Not yet, still srugling with it I'm new to PHP so not sure wher to be putting the command, my data base is generated by a software programme, got the entry to be accepted but when it run it comes back with a 'function undefined errror'!!!


Ya man!!!





Similar Threads
Thread Thread Starter Forum Replies Last Post
begin php & mysql - chapter 12, user_form.php jon_stubber Beginning PHP 1 March 9th, 2006 10:57 AM
PHP Mysql with Flash based display robprell Beginning PHP 0 November 3rd, 2005 10:06 PM
sort by date mysql crmpicco Classic ASP Databases 1 March 4th, 2005 06:55 AM
mysql timestamp to php display lbunnell PHP Databases 2 January 20th, 2005 05:55 PM
Display all tables in a mySql database question mb92010 MySQL 1 April 9th, 2004 04:26 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.