1

Right, I'm receiving a date from my mySQL database, the date is saved in a YYYY-MM-DD format, I want to call this as a $date = row['date'] variable and then somehow re-order it in php so that it is a DD-MM-YYYY format instead, I am not sure how I can achieve this though.

Someone please help.

3 Answers 3

3
SELECT DATE_FORMAT(date_here, "%d-%m-%Y") FROM table_here
Sign up to request clarification or add additional context in comments.

1 Comment

Way to go! Always do the maximum using SQL and if really needed, manipulate with PHP.
2
$date = "2010-12-23";
echo date("d-m-Y" , strtotime($date));

3 Comments

But how would i use the date from the SQL database when using that?, sorry i'm a php amateur ):
You explain it yourself in your question... $date = row['date'] :-S
Oh my god D:, I'm sorry I just showed how much of an amateur I actually am lol, best answer :)
0

Use DateTime which is a new class in PHP5.

https://www.php.net/manual/en/datetime.construct.php

<?php
    try {
     $date = new DateTime('2000-01-01');
    } catch (Exception $e) {
        echo $e->getMessage();
        exit(1);
    }
    
    echo $date->format('d-m-Y');
?>

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.