Jump to content

Reverse Date from mySQL


petenaylor

Recommended Posts

Thanks for your quick reply!

 

That just shows today's date instead of the date from the DB?

 

How should I echo out the $date?

 

Pete

 

It doesn't like the format of the date you're storing... I had to test it to make sure. Your two options are to store the date in a different way (e.g. YYYY-MM-DD) or you can use another solution like just rearranging the numbers in the string.

 


$first = substr($showdata['date'], 4, 2);
$second = substr($showdata['date'], 2, 2);
$third = substr($showdata['date'], 0, 2);

$newDate = $first.$second.$third;

Link to comment
Share on other sites

You should really be storing the date in the correct format to begin with, but you can do what you're asking with MySQL's STR_TO_DATE() and DATE_FORMAT() functions as well, and it will probably be more efficient also.

 

SELECT DATE_FORMAT(STR_TO_DATE(`date`, '%y%m%e'), '%e%m%y') AS formatted_date FROM table

Link to comment
Share on other sites

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.