Solved

alter date format from 2013-08-11 14:23:14 to 11-08-2013 14:23

Posted on 2014-01-25
5
265 Views
Last Modified: 2014-01-25
hi

I have a database full of times in this format

year-month-day hour:minute:second

2013-08-11 14:23:14

When I show the on the page I want to re-write them using PHP to this format (UK), notice no seconds to display as well

day-month-year hour-minute

11-08-2013 14:23

full code please, not a page link
0
Comment
Question by:Neil Thompson
  • 3
5 Comments
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 39808658
You need the page link to learn how this works, so here it is:
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html

Scan that page for Producing "Pretty" Dates From ISO-8601 Dates

I'll show you how to use PHP date() for this in a moment with a tested and working code sample.
0
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 39808660
See http://www.laprbass.com/RAY_temp_neilt.php

The pattern is on line 11.

<?php // RAY_temp_neilt.php
error_reporting(E_ALL);


// SEE http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28348043.html
// REF http://www.php.net/manual/en/function.date.php

$old = '2013-08-11 14:23:14';
$new = '11-08-2013 14:23';

$get = date('d-m-Y H:i', strtotime($old));
if ($new == $get) echo 'SUCCESS!';

Open in new window

HTH, ~Ray
0
 
LVL 15

Expert Comment

by:Insoftservice
ID: 39808682
Try out this one

<html>
<head>
<title>PHP Script Execution</title>
</head>
<body>
<?php
   echo "<h1>Hello, PHP!</h1>";
   $date ="2013-08-11 14:23:14";
   echo "<br>".date("d-m-Y H:i",strtotime($date));
   
?>
</body>
</html>

Open in new window

0
 
LVL 3

Author Closing Comment

by:Neil Thompson
ID: 39809212
Many thanks Ray, Needed the code as I had to have a bit of work completed earlier today and its easier to grab it working first, then spend the time of an evening learning. (thanks to you I've done both)

Regards, Neil
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 39809255
Glad to help, Neil.  Thanks for the points and thanks for using EE, ~Ray
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question