.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

How to calclute total time for a week

Posted By: Naresh     Posted Date: September 29, 2010    Points:2   Category :ASP.Net
Hi All,


I have totalTime for eachDay in string variable.I am usin forloop to loop through 7 days totaltime.While entering into loop i want to calculate Presnt TotalTime with previous day TotalTime.similarly for 7 days.I want total time for 1 week.
TotalTime like this 9:00
If i store it in string i cannot add String values.What is the better option.Date i have seperate column.Time should be seperate.

Responses
Author: Jean Paul             
Posted Date: September 29, 2010     Points: 5   

We have to use the TimeSpan class for this.

Example:

DateTime first = DateTime.Today;
DateTime second = DateTime.Today.AddDays(-1);

TimeSpan span = first - second;

span = span.Add(span);

double days = span.TotalDays;

Jean Paul http://jeanpaulva.com/
Author: Santosh             
Posted Date: October 04, 2010     Points: 5   

hi Naresh

just convert the store string to TimeSpan.

then u can compare and get the difference...

ex: VB.net Code
Dim d As TimeSpan = CDate(string1).TimeOfDay
Dim d1 As TimeSpan = CDate(string2).TimeOfDay
Dim Minutes As Integer = (string1 - string1).TotalMinutes

now u will get the diff in Minutes...

hope above code will help u.....

Regards
Santosh



Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend