Solved

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

Posted on 2014-01-25
5
263 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 109

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 109

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 109

Expert Comment

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

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

785 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