Jump to content


Photo

Date Parsing and Displaying a Calender


  • Please log in to reply
3 replies to this topic

#1 Daguse

Daguse
  • Members
  • PipPip
  • Member
  • 26 posts

Posted 17 April 2006 - 03:35 AM

First off thanks for the help everyone.

I am looking to take dates from a MySQL DB that are formated like so "Sep 21 2005 03:04:55", pars them and then create a loop that will take the month "Sep" and year "2005" and display that info. The trick is I may have many date for the same month and year howevver I only wanted them listed once.

Thanks again for all of your help.

#2 ypirc

ypirc
  • Members
  • PipPipPip
  • Advanced Member
  • 54 posts

Posted 17 April 2006 - 04:23 AM

Okay, I couldn't find a MySQL command that outputs the date in your format...I could be wrong though...so in this SQL command I am first formatting your date to a format MySQL understands ... (YYYY-MM-DD etc..), then I am formatting it to only show the month and year using your date format "Sep 2005", and finally only displaying unique entries...please see below.

[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] DISTINCT(DATE_FORMAT(STR_TO_DATE(date_column, '%b %d %Y %T'), '%b %Y')) FROM table; [!--sql2--][/div][!--sql3--]


Obviously replace date_column with the name of your date column and table with the name of your table...

#3 Daguse

Daguse
  • Members
  • PipPip
  • Member
  • 26 posts

Posted 18 April 2006 - 03:44 PM

Thank you ypirc, I will try that and see how it work.

#4 Daguse

Daguse
  • Members
  • PipPip
  • Member
  • 26 posts

Posted 30 April 2006 - 07:54 PM

OK so I have made a few post and made some changes to my site to try and get this to work. So I just want you all to talk a look can my code and see if its right.

The dats in the DB are placed using the Timestamp function.

[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] DISTINCT(DATE_FORMAT(date_column , '%M %Y')FROM Tablename; [!--sql2--][/div][!--sql3--]

And this will echo somthing like: "November 2005" Right?

Again thanks for your help!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users