Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


How do I display the mysql stored date in my page in any format I choose? by spencertaylor
Posted: 22 Jun 04

The date values to pass from PHP code to the date field in your table should be:


This is the format that mysql holds the date in.  So pass this value to a variable and include it in your INSERT or UPDATE queries:

$today = date('Y-m-d-H-i-s');

Then the query is of the form:

UPDATE mytable SET mydatefield=$today

A nice way to display the entered date in your php pages is as follows, assuming you have the date field included in your SELECT query:


$date = $queryfieldarray['mydatefield']; //get the date from the field in my table
$dateArray = explode("-",$date); //explode this value using -
$year = $dateArray[0]; // the first exploded value
$month = $dateArray[1]; // the second exploded value
$daytime = $dateArray[2]; // the third which includes the day as a number and time as hours,minutes and seconds are separated by :
$datetimeArray= explode(" ",$daytime); // these are separated by a space so explode that to separate the day from the time
echo $day.'/'.$month.'/'.$year.' at '.$time;  //display the UK date style

Hope this helps everyone.

Back to PHP FAQ Index
Back to PHP Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close