Jump to content

Archived

This topic is now archived and is closed to further replies.

Daguse

Date Parsing and Displaying a Calender

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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, [color=red]'%b %d %Y %T'[/color]), [color=red]'%b %Y'[/color])) [color=green]FROM[/color] [color=orange]table;[/color] [!--sql2--][/div][!--sql3--]


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

Share this post


Link to post
Share on other sites
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 , [color=red]'%M %Y'[/color])[color=green]FROM[/color] [color=orange]Tablename;[/color] [!--sql2--][/div][!--sql3--]

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

Again thanks for your help!

Share this post


Link to post
Share on other sites

×

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.