# Php, mysql date issues

**URL:** <https://forum.kirupa.com/t/php-mysql-date-issues/182030>\
**Category:** Uncategorized\
**Created:** [March 15, 2006, 12:03am UTC](https://forum.kirupa.com/t/php-mysql-date-issues/182030 "2006-03-15T00:03:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sigepmest37](https://avatars.discourse-cdn.com/v4/letter/s/8491ac/32.png) [@sigepmest37](https://forum.kirupa.com/u/sigepmest37)\
**Post date:** [March 15, 2006, 12:03am UTC](https://forum.kirupa.com/t/php-mysql-date-issues/182030/1 "2006-03-15T00:03:49Z")

</div>

I am building a site for a band. I want to have a section which lists the upcoming shows they will be playing. The band will enter the dates in the mm-dd-yy format.

I’m having a few issues:

1. As I understand it MySQL formats dates as yyyy-mm-dd. How do convert the mm-dd-yy to the necessary yyyy-mm-dd?

2. On one page i will have a table in which i want to list the next 5 shows that they will be playing. I’m a little confused as to how I query only the shows that have dates later than the current day.

3. Similar to 1. When i DO display the dates how to i make them appear in mm-dd-yy format?

Thanks in advance for any help!

---

<div class="post-metadata">

**Author:** ![skyler](https://avatars.discourse-cdn.com/v4/letter/s/ecae2f/32.png) [@skyler](https://forum.kirupa.com/u/skyler)\
**Post date:** [March 22, 2006, 6:37pm UTC](https://forum.kirupa.com/t/php-mysql-date-issues/182030/2 "2006-03-22T18:37:17Z")

</div>

> [@Voccart](#):
>
> to query the next 5 gigs and in the right date format. you can do it in one go…let mySql do all the work
> 
> ```php
> 
> $query= "SELECT gig, DATE_FORMAT(gig_date,'%d-%m-%Y') AS myDate
> FROM myTable 
> WHERE gig_date >= NOW() 
> ORDER BY gig_date DESC LIMIT 5";
> 
> ```

I am working on this EXACT PROBLEM! The code right there works… the only problem is, it is ordering alphabetically (changed the format of date so that it executes as “Monday, March 21, 2006”.

I have several dates following, but they are out of order. They are ordering alphabetically. I need them to order by their actual dates.

Hurry, this problem is very important.

//sky

---

<div class="post-metadata">

**Author:** ![Voccart](https://avatars.discourse-cdn.com/v4/letter/v/ea5d25/32.png) [@Voccart](https://forum.kirupa.com/u/Voccart)\
**Post date:** [March 22, 2006, 11:34pm UTC](https://forum.kirupa.com/t/php-mysql-date-issues/182030/3 "2006-03-22T23:34:40Z")

</div>

> [@skyler](#):
>
> Hurry, this problem is very important.

ill do my best 😉

```php
$query= "SELECT gig, DATE_FORMAT(gig_date,'%W, %M %d, %Y') AS myDate 
FROM myTable 
WHERE gig_date >= NOW() 
ORDER BY gig_date DESC 
LIMIT 5";
 
...
 
while ($Res = mysql_fetch_assoc($result)) 
{ 
echo $Res['gig']." - ". $Res['myDate']."<br>";
} 

```

Output:  
Gig1 - Wednesday, March 21, 2007  
Gig2 - Monday, March 19, 2007  
Gig3 - Monday, March 12, 2007  
etc…
