Daguse Posted April 17, 2006 Share Posted April 17, 2006 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 https://forums.phpfreaks.com/topic/7576-date-parsing-and-displaying-a-calender/ Share on other sites More sharing options...
ypirc Posted April 17, 2006 Share Posted April 17, 2006 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 https://forums.phpfreaks.com/topic/7576-date-parsing-and-displaying-a-calender/#findComment-27613 Share on other sites More sharing options...
Daguse Posted April 18, 2006 Author Share Posted April 18, 2006 Thank you ypirc, I will try that and see how it work. Link to comment https://forums.phpfreaks.com/topic/7576-date-parsing-and-displaying-a-calender/#findComment-28211 Share on other sites More sharing options...
Daguse Posted April 30, 2006 Author Share Posted April 30, 2006 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 https://forums.phpfreaks.com/topic/7576-date-parsing-and-displaying-a-calender/#findComment-32234 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.