seagull Posted March 8, 2006 Share Posted March 8, 2006 in my MSSQL tables the date is in the format ofyyyy-mm-dd hh:mm:ss.I am trying to get a report in the format:Date Total Minutes2006-Mar-1 11002006-Mar-2 50042006-Mar-3 8000and so on.The group by DATE dont give the required output as the TIME also is in the DATE column.Any ideas are appreciated Quote Link to comment https://forums.phpfreaks.com/topic/4419-how-to-group-by-date-when-date-column-has-yyyy-mm-dd-hhmmss-format/ Share on other sites More sharing options...
obsidian Posted March 8, 2006 Share Posted March 8, 2006 [!--quoteo(post=352794:date=Mar 8 2006, 06:08 AM:name=seagull)--][div class=\'quotetop\']QUOTE(seagull @ Mar 8 2006, 06:08 AM) [snapback]352794[/snapback][/div][div class=\'quotemain\'][!--quotec--]in my MSSQL tables the date is in the format ofyyyy-mm-dd hh:mm:ss.I am trying to get a report in the format:Date Total Minutes2006-Mar-1 11002006-Mar-2 50042006-Mar-3 8000and so on.The group by DATE dont give the required output as the TIME also is in the DATE column.Any ideas are appreciated[/quote]i'm not sure if this will work in MSSQL or not, but in MySQL, you can call the DATE() function on the column that has a datetime, and it only returns the date portion of it, so you can group by it... something like this:[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] DATE(dateColumn) [color=green]AS[/color] date, [color=blue]SUM[/color](minutes) [color=green]as[/color] total GROUP BY date;[!--sql2--][/div][!--sql3--]hope this helps Quote Link to comment https://forums.phpfreaks.com/topic/4419-how-to-group-by-date-when-date-column-has-yyyy-mm-dd-hhmmss-format/#findComment-15370 Share on other sites More sharing options...
GeoffOs Posted May 17, 2006 Share Posted May 17, 2006 You could use the convert function on your datetime column to change it into a date only column, for example[code]select convert(varchar(11), getdate(), 106)[/code]which returns[code]17 May 2006[/code]More details are available from msdn here [a href=\"http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_ca-co_2f3o.asp\" target=\"_blank\"]Cast and Convert MSDN Article[/a]I think you can use this result within your group by clause, though I have not tested this. Quote Link to comment https://forums.phpfreaks.com/topic/4419-how-to-group-by-date-when-date-column-has-yyyy-mm-dd-hhmmss-format/#findComment-36642 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.