473,396 Members | 2,102 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

DateDiff function returning incorrect results in asp.net 2.0 vb

I am trying to return the difference in minutes from a starttime and stoptime
using the datediff function in a Web Project with VB.Net

With:
StartTime = 2/10/2006 8:46:03 PM
EndTime = 2/10/2006 8:48:10 PM

I am getting a return value of 1054586688 in the diff variable

I tryed this same code in a Windows.Net Project and I get a return of 2 as I
would expect.

Can someone tell me what I need to do in a Web Project to make this simple
code work?
Code from Web Project
==================

Partial Class _Default
Inherits System.Web.UI.Page

Dim StartTime As Date

Protected Sub btnStartTime_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnStartTime.Click
StartTime = Now
lblStartTime.Text = StartTime
End Sub

Protected Sub btnStopTime_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnStopTime.Click
Dim EndTime As Date = Now
lblStopTime.Text = EndTime
Dim Diff As Integer = DateDiff(DateInterval.Minute, StartTime,
EndTime)
txtTime.Text = Diff

End Sub
End Class
Feb 11 '06 #1
7 6479
Reney,

This code will in my idea never works, you have to do with needed time for
sending and getting your page from the server. This kinds of actions on a
webclient need JavaScript, in your place would I search for JavaScript
StopWatch on Google.

I hope this helps,

Cor
Feb 11 '06 #2
Hi Cor,

What I am trying to do is create a timeslip to time work on a issue. The
tech can start the clock and stop the clock. I also want to have a text box
displaying the differences between the two time that can be edited.

I believe you when you say it can't be done with the code I displayed in my
post (I know that :)

What I need is a code example on how I can make this work and I am also
curious as to why this code works in a windows application but not in a Web
project.

If I could ask you to expand your answer that would be most helpful. And
yes I am new to Web development (sorry I am DBA that got tossed into
developement)
Feb 11 '06 #3
Ok Cor you can do this with vb.net - what I was missing was session.

here is the code that works in vb

Partial Class Default2
Inherits System.Web.UI.Page
Dim StartTime As Date

Protected Sub btnStartTime_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnStartTime.Click
Session("StartTime") = Date.Now
lblStartTime.Text = Session("StartTime")
End Sub

Protected Sub btnStopTime_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnStopTime.Click
Dim EndTime As Date
Session("EndTime") = Date.Now
Dim Diff As TimeSpan
Diff = Session("EndTime") - Session("StartTime")
txtTime.Text = Diff.Hours & ":" & Diff.Minutes & ":" & Diff.Seconds
lblStopTime.Text = Session("EndTime")
End Sub
End Class
Feb 12 '06 #4
Reney,

The result is not interesting because what you calculate is in my opinion
without sense.

The user clicks the button start time
The page is sent back to the server
The start time is set
The page is sent back to the client
The user clicks the button stop time
The page is sent back to the server
The time elapsed is calculated
The page is sent back to the client.
The user sees an elapsed time

What time did you measure?

Cor
Feb 12 '06 #5
Gee wiz Cor you must be having a bad day! The measure is the difference
between the start and end time someone worked on a support ticket for a time
tracking system. I simpified the example I posted to make it easier to fit in
the post.

And the question had pretty good logic behind it - in a windows app the code
works but additional code (wrapping the variable in Session) is needed for a
web application.

Feb 13 '06 #6
Reney,
Gee wiz Cor you must be having a bad day!


You could be right, however beside this text can you than explain how your
solution can work?

Your sample show in my idea that it does not work for webapplication. Do you
have sample that works.=?

Beside that it gives technical a result. However the result is something
what measures something that can never been asked because even when it would
measure the sending and retrieving time it is incorrect..

Cor
Feb 13 '06 #7
Reney,

By the way, you should not test this on your testing computer however on a
real internet or heavily occupied intranet (your testing computer will
probably reach the result you want).

Cor
Feb 13 '06 #8

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

Similar topics

8
by: inamori | last post by:
I face that problems 07/01/2003 06/30/2006 ---------> it should be 3 01/01/2003 02/28/2005 --------->could i get 2 years and 2 months 01/01/2003 03/01/2005 ...
4
by: Paolo | last post by:
I am having some problem with a Year Function. I have form on which I have 4 field which indicate dates and an additional form which sums those dates: These are the fields: YEARS...
3
by: Price Brattin | last post by:
Why is the DateDiff function in the following code returning zero? Dim FileDate, TransmissionDate as Date Dim TranDay, FileDay, DayDiff as Inteter TransmissionDate = #2/5/2006 1:57:56 PM#...
4
by: J-P-W | last post by:
Hi, I have a system that records insurance policies. If the policy is cancelled then any part of a month insured is deducted from the premium, so a policy that ran for 32 days would get a 10...
18
by: svata | last post by:
Hello to all, as a result from my previous post I'm busy with splitting code into functions. The one problem ( out of many ) I encounter is how to properly use/code a function which returns...
9
by: StevoNZ | last post by:
Hi, I am a little stuck with a query I am trying to build. Attemting to calculate the delivery time for a material. I have managed to utilise the DateDiff function, but have some additional...
2
by: stephenmcnutt | last post by:
I'm trying to do something that should be trivial. I'm a teacher at an elementary school, and I'm setting up an ASP form page for teachers to vote each afternoon on which dismissal line behaved...
10
klarae99
by: klarae99 | last post by:
I am working on an Inventory Database in Access 2003. I am having trouble with a report I designed to show current inventory in stock. I have a form (frmInventory) that is unbound. There are four...
4
by: OzNet | last post by:
I have some functions to calculate the working days in a given period. This includes a table that is queried to calculate the number of public holidays that don’t occur on a weekend. If I test...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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
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...
0
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...

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.