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 January 18th, 2005, 04:45 PM
Registered User
Join Date: Jan 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default mysql timestamp to php display

Teaching myself to program in php....

I have a timestamp in my mysql database that looks like this: 20041113105908. I'd like to display it to look like this 11/13/2003 in one column and 10:59:08 in another.

Here's what I've got:

<?php echo date('m/d/y', strtotime($row_rsUsers['EntryDate'])); ?>


<?php echo date('H:i:s', strtotime($row_rsUsers['EntryDate'])); ?>

but this doesn't seem to get it. What am I doing wrong.


Old January 18th, 2005, 05:59 PM
Friend of Wrox
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts

Try this:

$date = $row_rsUsers['EntryDate'];

$year = substr($date,0,4);
$month = substr($date,4,2);
$day = substr($date,6,2);
$hour = substr($date,8,2);
$minute = substr($date,10,2);
$second = substr($date,12,2);

//then echo them how you wish
echo $month."/".$day."/".$year;
echo $hour.":".$minute.":".$second;

-Snib - http://www.snibworks.com
Where will you be in 100 years?
Old January 20th, 2005, 05:55 PM
Friend of Wrox
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts

What is the data type of your MySQL column? If it's the DATETIME type, there are LOTS of mysql functions you can use in your SQL query to format the date however you want.

If it's an integer, then using arithmetic operations will probably be faster and more efficient than using the substr() method posted above. If it's a string, then you're more or less stuck slicing up the string.

You can do this using substr() as above or using a regular expression matching function, like preg_match().

// year month day hour minute second

$matches is an array that will contain all the matched strings.

$matches[0] will be the entire original string.
$matches[1] will be the year,
$matches[2] will be the month,
  ... and so on.


Take care,


Similar Threads
Thread Thread Starter Forum Replies Last Post
Timestamp display problem nareshphp PHP Databases 1 August 9th, 2007 12:20 AM
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
Display all tables in a mySql database question mb92010 MySQL 1 April 9th, 2004 04:26 PM
date mysql to php display Geeman PHP Databases 4 September 1st, 2003 08:13 AM

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