TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
durga prasad
NA
54
0
Calcalute hours between two date using timespan
Aug 9 2008 4:11 AM
Hi,
How calcalute total working hours between two date using timespan/date time pickers.
My code looks something like this, I am able to calculate for today but when the employee works for extra hours, for example he come today at 5pm and leaves by 5am in the next day, then how do i calculate?
TimeSpan ts = new TimeSpan();
ts = dtpouttime.Value.TimeOfDay - tpintime.Value.TimeOfDay;
ts = ts.Subtract(TimeSpan.FromMinutes(30));
if (ts.TotalHours <= 8.30)
{
txtworkedhours.Text = Convert.ToDecimal(ts.TotalHours).ToString("#0.00");
txtextrahours.Text = "";
//calc2.Text = calc1.Text;
calc1.Text = ts.ToString();
}
else if (ts.TotalHours >= 8.31)
{
calc1.Text = "";
calc2.Text = "";
txtextrahours.Text = "";
txtworkedhours.Text = "";
TimeSpan ts4 = new TimeSpan(8, 30, 0);
txtworkedhours.Text = (Convert.ToDecimal(Convert.ToDecimal(ts4.TotalHours)).ToString("#0.00"));
calc1.Text = ts4.ToString();
TimeSpan ts3 = new TimeSpan
ts3 = ts.Subtract(TimeSpan.FromHours(9) - (TimeSpan.FromMinutes(30)));
txtextrahours.Text = Convert.ToDecimal(ts3.TotalHours).ToString("#0.00");
calc2.Text = ts3.ToString();
}
else
{
MessageBox.Show("Invalid input");
}
Thanks in Advance,
A.Durga Prasad
Reply
Answers (
1
)
Stand by & Wake up
Error in declare new Form Part 2