@ PageLanguage="vb" AutoEventWireup="false" CodeBehind="test1.aspx.vb" Inherits="gfln1.test1" %>
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
htmlxmlns="http://www.w3.org/1999/xhtml" >
headrunat="server">
title>title>
head>
scriptsrc="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js">script>
scriptsrc="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.0/jquery-ui.min.js">script>
linkhref="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/base/ui.all.css" rel="stylesheet" type="text/css" />
scriptsrc="http://projectcodegen.com/jquery.ui.datetimepicker.js" type="text/javascript">script>
head>
scripttype="text/javascript">
$(function() {
$('#TextBox1').datetimepicker();
$('#TextBox2').datetimepicker();
});
script>
body>
formid="form1" runat="server">
div>
Enter Start Date/Timeasp:TextBoxID="TextBox1" runat="server">asp:TextBox>
Enter End Date/Timeasp:TextBoxID="TextBox2" runat="server">asp:TextBox>
Enter Conference daysasp:TextBoxID="TextBox3" runat="server">asp:TextBox>
br />
asp:ButtonID="Button1" runat="server" Text="Calculate Hours For businees" />
div>
form>
body>
html>
i want that if i click on button it gives me time differnce b/w just two time not date time
for example
Code
if textbox1 contain "12/24/2010 07:11 PM" and textbox2 contain "12/25/2010 08:11 AM"
and i want to calcaute just difference in hr b/w two time ,not datetime then i have t1 = Convert.ToDateTime(Me.TextBox1.Text).ToLongTimeString() t2 = Convert.ToDateTime(Me.TextBox2.Text).ToLongTimeString()
Dim tsdiff As TimeSpan = t2.Subtract(t1)
it should give 13 hours but right now its giving me -11 hours , can any oen help me
5 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Sam HobbsRank #108 · 20.5K reputationPosted Dec 24, 2010, 12:44 PM EST
0
You should use C#. When I try to convert your VB code to C# it won't let me call DateTime.Subtract since t2 is a string.
Don't call ToLongTimeString and make t1 and t2 DateTime objects instead of string objects. Note that I would post my code that I tested and that works the way you expect it to but my code is in C#.
erum mirzaRank #3,517 · 413 reputationPosted Dec 24, 2010, 4:09 PM EST
0
ok ,fine
0
Suthish NairRank #92 · 22.8K reputationPosted Dec 24, 2010, 8:49 PM EST
0
If you want to find exact time from a datetime then you need to use Date also.
VB.NET
Dim startTime As DateTime, endTime As DateTime
startTime = Convert.ToDateTime("12/24/2010 07:11 PM")
endTime = Convert.ToDateTime("12/25/2010 08:11 AM")
Dim timeDiff = New TimeSpan(endTime.Ticks - startTime.Ticks)
'timeDiff.Hours
erum mirzaRank #3,517 · 413 reputationPosted Dec 25, 2010, 2:32 AM EST
0
well nair thanks for ur so help ,but let me tell u shortly whole scanerio .my problem is that i have to calculate businees hours for conference .
for example conference go for 2 days say 25 dec and 26 dec ,now for time it should be 12 hours daily on both days ,for example time may be 5:00pm to 5 :am means 12 hours
that means conference will go 12 hours daily ,i need to so this
I hope u got my oint
0
Sam HobbsRank #108 · 20.5K reputationPosted Dec 25, 2010, 12:57 PM EST
0
This is the VB version.
VB.NET
Dim st1 AsString = "12/24/2010 07:11 PM"Dim st2 AsString = "12/25/2010 08:11 AM"Dim t1 As DateTime = Convert.ToDateTime(st1)
Dim t2 As DateTime = Convert.ToDateTime(st2)
Dim tsdiff As TimeSpan = t2.Subtract(t1)
Sam HobbsRank #108 · 20.5K reputationPosted Dec 24, 2010, 12:44 PM EST
Don't call ToLongTimeString and make t1 and t2 DateTime objects instead of string objects. Note that I would post my code that I tested and that works the way you expect it to but my code is in C#.
erum mirzaRank #3,517 · 413 reputationPosted Dec 24, 2010, 4:09 PM EST
Suthish NairRank #92 · 22.8K reputationPosted Dec 24, 2010, 8:49 PM EST
Dim startTime As DateTime, endTime As DateTime startTime = Convert.ToDateTime("12/24/2010 07:11 PM") endTime = Convert.ToDateTime("12/25/2010 08:11 AM") Dim timeDiff = New TimeSpan(endTime.Ticks - startTime.Ticks) 'timeDiff.Hourserum mirzaRank #3,517 · 413 reputationPosted Dec 25, 2010, 2:32 AM EST
for example conference go for 2 days say 25 dec and 26 dec ,now for time it should be 12 hours daily on both days ,for example time may be 5:00pm to 5 :am means 12 hours
that means conference will go 12 hours daily ,i need to so this
I hope u got my oint
Sam HobbsRank #108 · 20.5K reputationPosted Dec 25, 2010, 12:57 PM EST