| | |
Time difference in vb.net
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Apr 2008
Posts: 4
Reputation:
Solved Threads: 0
Hi all,
I'm having the situation to calculate as follows: The time difference between 4:00pm and 1:00 am is 9 hours. This is derived by subtracting 4 from 12 which equals 8 and adding 1 hour for the time between 12:00 and 1:00. I'm having 2 datetimepicker in starttime i've given 4:00 pm and endtime i've given 1:00 am..
i'm having starttime as datetime and endtime as datetime.. How to get the time difference in hours.. In this i've kept datetimepicker format as custom and custom format as "HH:mm:ss"..
Thanks in advance
I'm having the situation to calculate as follows: The time difference between 4:00pm and 1:00 am is 9 hours. This is derived by subtracting 4 from 12 which equals 8 and adding 1 hour for the time between 12:00 and 1:00. I'm having 2 datetimepicker in starttime i've given 4:00 pm and endtime i've given 1:00 am..
i'm having starttime as datetime and endtime as datetime.. How to get the time difference in hours.. In this i've kept datetimepicker format as custom and custom format as "HH:mm:ss"..
Thanks in advance
Hi!
This is what I did. I'm writing this @ 14:25 and hence added some hours to simulate your situation. I'm directly taking the datetime but you can do the same from the datetimepicker.
This is what I did. I'm writing this @ 14:25 and hence added some hours to simulate your situation. I'm directly taking the datetime but you can do the same from the datetimepicker.
vb.net Syntax (Toggle Plain Text)
Public Class Form1 Dim d1, d2, d3 As DateTime Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load d1 = Now.AddHours(2) d2 = Now.AddHours(11) Me.TextBox1.Text = d1 Me.TextBox2.Text = d2 End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click d3 = (d2 - d1).ToString Me.TextBox3.Text = d3 End Sub End Class
My blog on .NET- http://dotnet.tekyt.info
Alternatively, you can use a Timespan object. I guess this is more elegant-
vb.net Syntax (Toggle Plain Text)
Public Class Form1 Dim d1, d2 As DateTime Dim x As TimeSpan Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load d1 = Now.AddHours(2) d2 = Now.AddHours(11) Me.TextBox1.Text = d1 Me.TextBox2.Text = d2 End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click x = d2 - d1 Me.TextBox3.Text = x.ToString End Sub End Class
My blog on .NET- http://dotnet.tekyt.info
nice codes
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
So, Please do something before post your thread.
* PM Asking will be ignored *
![]() |
Similar Threads
- I need .NET basic interview questions urgently (C#)
- Difference between DLL & Process ??? (C++)
- Calculating Time Difference (C++)
- asp.net tutorial (ASP)
- The Move.....Visual Basic 6, Visual Basic .NET ? (VB.NET)
- VB .net vs VS .net (VB.NET)
- Dummy in VB (Visual Basic 4 / 5 / 6)
- Difference (Web Browsers)
Other Threads in the VB.NET Forum
- Previous Thread: user input to add to ms sql query
- Next Thread: Contactless Card Reader problem
| Thread Tools | Search this Thread |
.net 2005 2008 access account arithmetic array arrays basic bing button buttons c# center check checkbox code combobox component convert crystalreport data database datagrid datagridview date dissertation dissertations dropdownlist excel fade file-dialog folder ftp generatetags google gridview hardcopy images inline input insert intel internet listview mobile monitor ms net networking objects output passingparameters peertopeervideostreaming picturebox picturebox1 port print printing problem problemwithinstallation project remove save searchbox searchvb.net select serial server shutdown soap sorting survey table tcp temperature text textbox timer toolbox trim update updown user validation vb vb.net vb.netcode vb.netformclosing()eventpictureboxmessagebox vb2008 vbnet view visual visualbasic visualbasic.net visualstudio visualstudio2008 web winforms wpf






