MySQL Date to PHP Date

Hi,

I am displaying a date called from a MySQL database, however, the mySQL date is showing as 2013-04-27, however, I need it to display as 27-04-2013 but I don’t know how.

Any help would be grateful.

You can do that with the SELECT statement, something like:

SELECT DATE_FORMAT(DateField, ‘%d-%m-%Y’) AS SomeDate FROM tbl_Name WHERE …

Hi

Thank you for your help. Could you please advise where I put this code? Also do I replace the current $sql = statement with the code you provided?

Sorry I am still learning all of this.

You need to modify your existing SELECT statement with:

DATE_FORMAT(DateField, ‘%d-%m-%Y’) AS SomeDate

WHERE DateField is whatever your date field is called and SomeDate is whatever you want to call your formatted date.

Hi,

Okay so now my SQL query looks like this;

$sql = “select * DATE_FORMAT(Arrival, ‘%d-%m-%Y’) AS SomeDate from reserve where ReservationNumber = $ReservationNumber”;

but it now no longer reconises the reservation number.

Thank you for your continued help.

Try this:

$sql = “SELECT *, DATE_FORMAT(Arrival, ‘%d-%m-%Y’) AS SomeDate FROMreserve WHERE ReservationNumber =” . $ReservationNumber;

Hi,

That has stopped the error now and the reservation numbers are again reconised, however, the date format is still 2013-04-27.

Thanks

I fixed it. I changed the SomeDate to Arrival to match to $Arrival.

Thank you ever so much :slight_smile:

Sponsor our Newsletter | Privacy Policy | Terms of Service