|
-
Jan 12th, 2010, 06:19 AM
#1
Thread Starter
Lively Member
[RESOLVED] Date and Time Calculation
Hi all.
Can someone please provide code for the following calculations using dates and times. I have hit a brick wall with this .
if the current hour is less than 21:00 (today) then show the remaining time in label3 as hh:mm:ss remaining. However, if the current hour is greater than 21:00 then show show the remaining time calculated in hh:mm:ss from 21:00 on the next day.
Any help would be appreciated.
Regards
Colin
-
Jan 12th, 2010, 07:36 AM
#2
Re: Date and Time Calculation
Code:
Dim whenDT As DateTime = #9:00:00 PM#
Dim dt As DateTime = DateTime.Now
If dt.TimeOfDay >= whenDT.TimeOfDay Then
Else
End If
-
Jan 12th, 2010, 07:48 AM
#3
Thread Starter
Lively Member
Re: Date and Time Calculation
 Originally Posted by dbasnett
Code:
Dim whenDT As DateTime = #9:00:00 PM#
Dim dt As DateTime = DateTime.Now
If dt.TimeOfDay >= whenDT.TimeOfDay Then
Else
End If
Thanks. Could you provide the code that actually does the calculation. Sorry if my post is a bit misleading, I tried to word it as best I could.
Regards
Colin
-
Jan 12th, 2010, 08:04 AM
#4
Re: Date and Time Calculation
Not sure what calculation you mean, but I'll guess
Code:
Dim dt As DateTime = DateTime.Now
Dim whenDT As DateTime = dt.Date.AddHours(21)
Dim elaps As New TimeSpan
If dt.TimeOfDay > whenDT.TimeOfDay Then
whenDT = whenDT.AddDays(1)
End If
elaps = whenDT - dt
'read about timespan
Debug.WriteLine(elaps.ToString)
Last edited by dbasnett; Jan 12th, 2010 at 09:19 AM.
-
Jan 12th, 2010, 09:10 AM
#5
Thread Starter
Lively Member
Re: Date and Time Calculation
I'll see if I can define the required calculations a bit better.
If the current system time hours < 21:00 then calculate the time difference between current time and 21:00 (formatted as HH:mm:ss)
else if the current system time > 21:00 then calculate the time difference between current system and 21:00 tomorrow (again formatted as HH:mm:ss).
Hope this is a bit clearer. Sorry for the confusion with my original post.
Regards
Colin
-
Jan 12th, 2010, 09:20 AM
#6
Re: Date and Time Calculation
 Originally Posted by wearmc
I'll see if I can define the required calculations a bit better.
If the current system time hours < 21:00 then calculate the time difference between current time and 21:00 (formatted as HH:mm:ss)
else if the current system time > 21:00 then calculate the time difference between current system and 21:00 tomorrow (again formatted as HH:mm:ss).
Hope this is a bit clearer. Sorry for the confusion with my original post.
Regards
Colin
Except for the formatting, that is what you have. BTW - What about
current system time = 21:00 ??????
If the current time is before 9PM on this date then show how long till 9PM this date
else show how long till 9PM tomorrow
-
Jan 12th, 2010, 09:35 AM
#7
Thread Starter
Lively Member
Re: Date and Time Calculation
Sorry, didn't understand your code. I thought it was only accounting for the time difference on the same day. My apologies. Will mark thread as resolved.Thanks for your help.
Regards
Colin
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|