0

I am trying to format data from my MySQL database on a php HTML site. The date in MySQL looks like the following

2015-07-10 03:17:00

I would like to have it formatted like this

10-07-2015 03:17

It will then be display in a HTML form as below

<td>Open MT4 Time:</td>
<td><input type="datetime-local" name="openmt4time" value="<?php echo $row['openmt4time']; ?>"</td>

Any help will be greatly appreciated Thanks

5 Answers 5

3

$row['openmt4time'] = date_format($row['openmt4time'],"d-m-Y H:i");

Sign up to request clarification or add additional context in comments.

Comments

1

I use this for format dates:

$date = $row['DateFromDB'];
$fecha = new DateTime($date);
$newdate = $fecha->format('d-m-Y H:i');
echo $newdate;

That should help too!

1 Comment

Hi, sorry I made a mistake. The format for it to work it ":1996-12-19T16:39:57". Do you know how to do this ?
1

You can convert it with the date(); function.

date("d-m-Y H:i", strtotime($row['openmt4time']));

This should ouput the format you're looking for.

Comments

1
  1. To format the date with MySQL you can use the function DATE_FORMAT()

    SELECT DATE_FORMAT(your_date_column_name,'%d %m %Y %h:%i') AS openmt4time FROM table_name

Now the $row['openmt4time'] will be having the formated date. Just echo it.

Learn about more date formats here

  1. In PHP you can format the date by using the date function as follows date("d-m-Y H:i", strtotime($your_non_formated_date_string));

Comments

0

Try This,

if your format is

$YOUR_DATE = '2015-07-20 09:05';
date('Y-m-d H:i', strtotime($YOUR_DATE));

if your format is

$YOUR_DATE = '20-07-2015 09:05';
date('d-m-Y H:i', strtotime($YOUR_DATE));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.