Jump to content

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 |
+------------+------------+
  • Like 1
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.