473,667 Members | 2,703 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.P age

Dim StartTime As Date

Protected Sub btnStartTime_Cl ick(ByVal sender As Object, ByVal e As
System.EventArg s) Handles btnStartTime.Cl ick
StartTime = Now
lblStartTime.Te xt = StartTime
End Sub

Protected Sub btnStopTime_Cli ck(ByVal sender As Object, ByVal e As
System.EventArg s) Handles btnStopTime.Cli ck
Dim EndTime As Date = Now
lblStopTime.Tex t = EndTime
Dim Diff As Integer = DateDiff(DateIn terval.Minute, StartTime,
EndTime)
txtTime.Text = Diff

End Sub
End Class
Feb 11 '06 #1
7 6492
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.P age
Dim StartTime As Date

Protected Sub btnStartTime_Cl ick(ByVal sender As Object, ByVal e As
System.EventArg s) Handles btnStartTime.Cl ick
Session("StartT ime") = Date.Now
lblStartTime.Te xt = Session("StartT ime")
End Sub

Protected Sub btnStopTime_Cli ck(ByVal sender As Object, ByVal e As
System.EventArg s) Handles btnStopTime.Cli ck
Dim EndTime As Date
Session("EndTim e") = Date.Now
Dim Diff As TimeSpan
Diff = Session("EndTim e") - Session("StartT ime")
txtTime.Text = Diff.Hours & ":" & Diff.Minutes & ":" & Diff.Seconds
lblStopTime.Tex t = Session("EndTim e")
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
5923
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 --------->could i get 2 years and 2 months and 1
4
11910
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 STARTINGDATE1 ENDINGDATE1 STARTINGDATE2
3
13414
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# FileDate = #2/4/2006 4:49:02 PM# TranDay = DatePart(DateInterval.DayOfYear, TransmissionDate) 'Returns 36 FileDay = DatePart(DateInterval.DayOfYear, FileDate) 'Returns 35 DayDiff = DateDiff(DateInterval.DayOfYear, FileDate, TransmissionDate) 'Returns...
4
4441
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 month rebate so would 58 days etc. I've used:
18
2344
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 either array of characters(string) or a pointer to this array. I read some articles, some other posts and come to this solution:
9
2816
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 complexities. 1. The dates I am using are to calculate a more correct delivery time is not always populated, therefore I need to utilise a different date field. DateDiff("d",DTMORD,DATREC) AS Expr1 DateDiff("d",DTMORL,DATREC) AS Expr2
2
3420
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 best. I've done this sort of thing before. For example, I've set up a form page teachers use each day to record lunch counts. The results are saved to a database on the website, and a second ASP page displays the result using this "custom query":...
10
2191
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 combo boxes on this form that allow the user to select Location, Vendor, Category and SubCategory. These selections (or blank fields) are then passed on to a query (see SQL below) and a report opens to show the inventory. This worked really well...
4
3054
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 the function using the intermediate window, it works fine. However, when I pass the dates from the code attached to my form, the results are inaccurate. You will notice my dates are in Australian format. Everything works fine using the Australian...
0
8459
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8889
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8790
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8650
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6206
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5677
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4202
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2017
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1779
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.