Jump to content

PHP/MySQL date output


Mr_Irnonic

Recommended Posts

Hello dear members, first of all sorry for my grammer i'm from Switzerland  :happy-04: .

So now: I have a problem with php. I want to put out the date of a blogpost in this format dd:mm:yyyy instead of yyyy:mm:dd. I tried it a long time and used many different ways like: date, dateformat, strto etc. but at the and nothing worked for me. So here is a picture of the blogpost and i'll add the file with my compressd php code.

 

I'd be glad if you could help me ::)

Regards Mr_Ironic

wlxpo7qxrn2q.png

 

help.php

Link to comment
https://forums.phpfreaks.com/topic/292493-phpmysql-date-output/
Share on other sites

For the benefit of those looking for a solution, there are two ways

 

1. Using PHP date() function to format the date output

$sql = "SELECT 
            thedate 
        FROM dates";
$res = $db->query($sql);
list($thedate) = $res->fetch_row();
echo "| $thedate | " . date('d:m:Y', strtotime($thedate)) . " |<br>";

/* OUTPUT

| 2014-11-16 | 16:11:2014 |

*/

2. Using MySQL DATE_FORMAT() function

mysql> SELECT
    ->     thedate
    ->   , DATE_FORMAT(thedate, '%d:%m:%Y') as formatted
    -> FROM dates;

+------------+------------+
| thedate    | formatted  |
+------------+------------+
| 2014-11-16 | 16:11:2014 |
+------------+------------+

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.