Jump to content

Date Parsing and Displaying a Calender


Daguse

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.
Link to comment
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...
Link to comment
Share on other sites

  • 2 weeks later...
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!
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.