I am using this expression in an SQL query's SELECT clause to convert seconds into HH:MM:SS format.
CONVERT(char(8), DATEADD(second, duration, '0:00:00'), 108) AS duration
Now the problem with this is that I can't do calculations on this column at the front end (GridView), like a summary total of the duration at the bottom. I either have to split the string in each cell of the
duration to convert hours, minutes, seconds to seconds and do the calculations (haven't tried yet), or do the total of duration in the SQL query and send it back and then manipulate it to HH:MM:SS in code behind (thats what I am doing right
now using Stored procedures). This method was working fine until I tried GridView helper class
http://www.agrinei.com/gridviewhelper/gridviewhelper_en.htm to perform grouping and add the values in
duration column for each group. It adds it but like a string concatenation.
Is there way I can SELECT duration as seconds only without using that expression and then format it in the gridview as HH:MM:SS so that I can perform calculations at the front end. Any other suggestions...
CDate works on a valid date expression. I just want to display the seconds which is an integer value in hours, minutes and seconds. There is no date involved here.
They are just stored as integral seconds in one column. I found a way to deal with that (someone might have a better way). Since I am certain that when the seconds are displayed in gridview column in HH:MM:SS format (which I get from the expression I mentioned
in my initial post), I can just split the value of each cell and get the hours, minutes and seconds. Then I just multiply hours by 3600, minutes by 60, and add them to the remaining seconds. So I have two little funtions, one to convert HH:MM:SS into seconds
and the other to convert seconds back to HH:MM:SS. This works for now.
bullpit
All-Star
21838 Points
4822 Posts
GridView: Format seconds to HH:MM:SS
Jul 31, 2007 05:05 PM|LINK
Hi there,
I am using this expression in an SQL query's SELECT clause to convert seconds into HH:MM:SS format.
Now the problem with this is that I can't do calculations on this column at the front end (GridView), like a summary total of the duration at the bottom. I either have to split the string in each cell of the duration to convert hours, minutes, seconds to seconds and do the calculations (haven't tried yet), or do the total of duration in the SQL query and send it back and then manipulate it to HH:MM:SS in code behind (thats what I am doing right now using Stored procedures). This method was working fine until I tried GridView helper class http://www.agrinei.com/gridviewhelper/gridviewhelper_en.htm to perform grouping and add the values in duration column for each group. It adds it but like a string concatenation.
Is there way I can SELECT duration as seconds only without using that expression and then format it in the gridview as HH:MM:SS so that I can perform calculations at the front end. Any other suggestions...
Thanks all
Max
Let Me Google That For You!
codeasp
Star
14735 Points
2545 Posts
Re: GridView: Format seconds to HH:MM:SS
Jul 31, 2007 11:16 PM|LINK
<%# CDate(Eval("AddedDate")).ToString("HH:MM:ss") %>Does this help?bullpit
All-Star
21838 Points
4822 Posts
Re: GridView: Format seconds to HH:MM:SS
Aug 01, 2007 12:45 PM|LINK
Thanks codeasp but where do I use it?
Max
Let Me Google That For You!
codeasp
Star
14735 Points
2545 Posts
Re: GridView: Format seconds to HH:MM:SS
Aug 01, 2007 11:06 PM|LINK
You can use inside the Gridview, DetailsView, FormView, DataGrid etc etc. Following example uses gridview.
<asp:TemplateField> <ItemTemplate> <%# CDate(Eval("AddedDate")).ToString("HH:MM:ss") %> <Asp:Label runat="server" Text='<%# CDate(Eval("AddedDate")).ToString("HH:MM:ss") %>' /> </ItemTemplate> </asp:TemplateField>bullpit
All-Star
21838 Points
4822 Posts
Re: GridView: Format seconds to HH:MM:SS
Aug 02, 2007 11:46 AM|LINK
CDate works on a valid date expression. I just want to display the seconds which is an integer value in hours, minutes and seconds. There is no date involved here.
Max
Let Me Google That For You!
codeasp
Star
14735 Points
2545 Posts
Re: GridView: Format seconds to HH:MM:SS
Aug 02, 2007 09:12 PM|LINK
Can you tell the format of your hours minutes and seconds( how it is stored in db). Are they in different columns or in a single column etc.
bullpit
All-Star
21838 Points
4822 Posts
Re: GridView: Format seconds to HH:MM:SS
Aug 03, 2007 12:00 AM|LINK
They are just stored as integral seconds in one column. I found a way to deal with that (someone might have a better way). Since I am certain that when the seconds are displayed in gridview column in HH:MM:SS format (which I get from the expression I mentioned in my initial post), I can just split the value of each cell and get the hours, minutes and seconds. Then I just multiply hours by 3600, minutes by 60, and add them to the remaining seconds. So I have two little funtions, one to convert HH:MM:SS into seconds and the other to convert seconds back to HH:MM:SS. This works for now.
Max
Let Me Google That For You!