How to deal with DATE-type in MYSQL & PHP?
I'm building a website with php and i'm using the DATE-type in my MYSQL table to store dates. The problem that i have is that this stores the dates by default in the format YYYY-MM-DD. But i need this format DD-MM-YYYY to appear on my PHP page with the possibility of calculating the amount of days between 2 different dates. How can this be achieved?
That's a display problem. Use mysql's
function to convert to whatever your display requirements are, e.g.
You can use strtotime to convert a string representation of the date to an actual date object in php, then use the date function to spit out the date as any string format you wish. Also, you can be
strtotimeto perform date calculations. Additional information can be found at this blog post.
Here is an example for a way to do it:
Further example here: How to calculate the difference between two dates using PHP?