473,486 Members | 2,136 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Difference between two datetimes

Hello -

I have two dates stored in txtLogin and txtLogout textboxes. The format is
as follows:
txtLogin - 10/20/2008 8:03:00 AM
txtLogout - 10/20/2008 5:30:00 PM

I need to subract login from logout to get the total time worked for the day.

The Staffed time worked for the day needs to be displayed in a
datetimepicker (dtpStaff) control with the format of HH:mm:ss. [Done]

Also, login and logout are displayed in dtpLogin and dtpLogout with the
format of HH:mm:ss tt (the textboxes are not visible). [Done]

When login or logout are changed, the dtpStaff control needs to update.

My main problems: 1) How to subtract login from logout; 2) update the
dtpStaff control.

Thanks in advance for anyone who can be of assistance.
--
Sheldon
Nov 7 '08 #1
2 3275
To find the difference between two times currently stored as text, use code
such as the following:

Try
Dim dt1 as DateTime.Parse(txtLogin.Text)
Dim dt2 as DateTime.Parse(txtLogout.Text)
Dim diff As TimeSpan = dt2.Subtract(dt1)
Catch e as FormatException
<error processing>
End Try

How you will update the dtpStaff control depends on where the changed start
or end time data is coming from.

"Sheldon" <Sh*****@discussions.microsoft.comwrote in message
news:82**********************************@microsof t.com...
Hello -

I have two dates stored in txtLogin and txtLogout textboxes. The format
is
as follows:
txtLogin - 10/20/2008 8:03:00 AM
txtLogout - 10/20/2008 5:30:00 PM

I need to subract login from logout to get the total time worked for the
day.

The Staffed time worked for the day needs to be displayed in a
datetimepicker (dtpStaff) control with the format of HH:mm:ss. [Done]

Also, login and logout are displayed in dtpLogin and dtpLogout with the
format of HH:mm:ss tt (the textboxes are not visible). [Done]

When login or logout are changed, the dtpStaff control needs to update.

My main problems: 1) How to subtract login from logout; 2) update the
dtpStaff control.

Thanks in advance for anyone who can be of assistance.
--
Sheldon
Nov 7 '08 #2
Sheldon wrote:
I have two dates stored in txtLogin and txtLogout textboxes.
The format is as follows:
txtLogin - 10/20/2008 8:03:00 AM
txtLogout - 10/20/2008 5:30:00 PM
For a start, store your DateTime values in DateTime variables.

If you want the user to be able to see them then /additionally/ format
and display them.
I need to subract login from logout to get the total time worked for the day.
Dim ts as TimeSpan = dateLogout.Subtract( dateLogin )
When login or logout are changed, the dtpStaff control needs to update.
Define properties [on the Form] that allow these values to be updated,
changing both the DateTime variables holding the "real" values and
formatting the output into your TextBoxes (although you also say that
they TextBoxes are not visible, so why bother?)

Public Property LoginTime() as DateTime
Get
Return m_loginTime
End Get
Set( value as DateTime )
m_loginTime = value

Me.txtLoginText = m_loginTime.ToString( "MM/dd/yy HH:mm" )

Dim ts as new TimeSpan _
= m_logoutTime.Subtract( m_loginTime )

Me.txtElapsed.Text = ts.TotalMinutes.ToString()

End Set
End Property
Private m_loginTime as DateTime = DateTime.MaxValue

HTH,
Phill W.
Nov 10 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1154
by: Stewart Midwinter | last post by:
After an hour of research, I'm more confused than ever. I don't know if I should use the time module, or the eGenix datetime module. Here's what I want to do: I want to calculate the time...
4
983
by: Michael Pfeifer | last post by:
Hi all, I need to convert datetimes from any timezone to UTC and back considering daylight saving. It is not enough, to just add or subtract the timezone offset. Also, I can not use c functions...
2
2123
by: Javier | last post by:
Hi I need to retrieve data from a table comparing datetimes. I mean I've a table with a datetime data and I'll need to retrieve rows with date time > now and date time < now + 5 minutes... Is...
2
10977
by: Randall Parker | last post by:
I know I could just get the year,month,day, etc of of each DateTime vars and calc the hours difference between them. I've done this before in other languages with a formula for handling leap years....
3
1801
by: Pieter Coucke | last post by:
Hi, For some reason, somewhere in my application 1 hour is added to my dates, depending in which time zone the application is run... Because I don't have a clue where this happens, I posted this...
4
11424
by: Daves | last post by:
hi, how do I get the difference, in days, between two DateTime classes?
0
1253
by: Claes at work | last post by:
Hi, I am learning Python and want to perform what I think is a very simple task: calculating the difference between two dates in seconds. Reading through the documentation I am puzzled: I can't...
5
19794
by: Mike | last post by:
I use c#, V2005 How I can get difference between two dates and get value in month(s) I had found some solutions but it is not exactly what I need. private static int...
7
29760
by: 23rnj3mn32sdjqw | last post by:
Hi, It should be simple - but I am trying to find the difference between two datetimes as an integer in seconds. Using pywin32 build 212, python 2.5, Windows XP Pro, MySQL 5.0. import time...
0
7100
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6964
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7126
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7175
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6842
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
4865
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4559
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1378
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
598
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.