473,320 Members | 1,868 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,320 software developers and data experts.

How to compare time?

Hi Guys,

Just looking for the best way to compare two times.

What I want to do is make sure a time is in between two other times.

E.g. If the current time is 14.00 I want to check that it is between 13.30
and 14.30.

Would it be best be using the TimeSpan class?

Idealy I want to do:

If (Time1 > Time2) And (Time1 < Time3) then

'do stuff

End If

but that does not work correctly.

Thanks

James
Mar 29 '06 #1
3 1980
James,

The ideas about your question are different in this newsgroups.

In my idea if you only want to compare without knowing anything exact, than
the ticks can do everting for you (is a long value).

(The result value of ticks says almost nothing it started at 1-1-1 while the
calandars have changed during that time).

I hope this helps,

Cor

"James" <ra*@iexpress.net.au> schreef in bericht
news:ee*************@TK2MSFTNGP10.phx.gbl...
Hi Guys,

Just looking for the best way to compare two times.

What I want to do is make sure a time is in between two other times.

E.g. If the current time is 14.00 I want to check that it is between 13.30
and 14.30.

Would it be best be using the TimeSpan class?

Idealy I want to do:

If (Time1 > Time2) And (Time1 < Time3) then

'do stuff

End If

but that does not work correctly.

Thanks

James

Mar 29 '06 #2
"James" <ra*@iexpress.net.au> schrieb:
What I want to do is make sure a time is in between two other times.

E.g. If the current time is 14.00 I want to check that it is between 13.30
and 14.30.

Would it be best be using the TimeSpan class?

Idealy I want to do:

If (Time1 > Time2) And (Time1 < Time3) then

'do stuff

End If

but that does not work correctly.

What exactly does not work correctly?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Mar 29 '06 #3
James,
Generally I use a TimeRange class.

http://www.tsbradley.net/Cookbook/Pa...timeRange.aspx

Dim range As New TimeRange(#13:30:00 PM#, #14:30:00 AM#)

If range.Contains(Time1) then
'do stuff
End If

Although TimeRange accepts DateTime parameters, internally it is represented
as TimeSpan objects.

(Yes I need to update the descriptions on that page).

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"James" <ra*@iexpress.net.au> wrote in message
news:ee*************@TK2MSFTNGP10.phx.gbl...
| Hi Guys,
|
| Just looking for the best way to compare two times.
|
| What I want to do is make sure a time is in between two other times.
|
| E.g. If the current time is 14.00 I want to check that it is between 13.30
| and 14.30.
|
| Would it be best be using the TimeSpan class?
|
| Idealy I want to do:
|
| If (Time1 > Time2) And (Time1 < Time3) then
|
| 'do stuff
|
| End If
|
| but that does not work correctly.
|
| Thanks
|
| James
|
|
Mar 30 '06 #4

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

Similar topics

1
by: Cameron | last post by:
Using SQL data compare i get the following error message: Could not allocate space for object '(SYSTEM table id: -701903460)' in database 'TEMPDB' because the 'DEFAULT' filegroup is full. The...
4
by: Sunit Joshi | last post by:
Hello All I'm trying to figure out how to do this the best way. Basically, I need to compare DateTime of files across TimeZones. The situation is like this: 1. I have a database say in Korea...
1
by: Manny Chohan | last post by:
i have two date fields for event start date and end date. I let the user enter two on create event page. on submit, i need to compare if the end date is earlier than start date or not. How can i...
5
by: rcolby | last post by:
Evening, Wondering if someone can point me in the right direction, on how I would compare a system.guid with a system.byte. system.guid (pulled from sql server table with a data type of...
12
by: Assimalyst | last post by:
Hi, I have a working script that converts a dd/mm/yyyy text box date entry to yyyy/mm/dd and compares it to the current date, giving an error through an asp.net custom validator, it is as...
3
by: thomson | last post by:
Hi, I have 5 aspx pages, In one page i have a Compare Validator Control, The four aspx pages are loading fast with similar controls, no code behind, But the page having Compare Validator Control...
4
by: Jim Langston | last post by:
Is there any builtin lowercase std::string compare? Right now I'm doing this: if ( _stricmp( AmmoTypeText.c_str(), "GunBullet" ) == 0 ) AmmoType = Item_Ammo_GunBullet; Is there anything the...
1
by: Will | last post by:
This little puzzle has been bugging me for some time. I'm trying to create a little service that will check a time frame and compare it to another timeframe (start / stop time). A real-world...
1
by: cssExp | last post by:
Hi, Assume i have two tables. "accounts" and "accounts_logs" "accounts" (accid, type) "accounts_log" (accid, ip, timestamp) Here i want to choose a radom 3 accids from "accounts" if...
3
by: =?Utf-8?B?U2FuZHBvaW50R3V5?= | last post by:
string dateTime = "5/28/2008"; DateTime.Compare(DateTime.Now,DateTime.Now) // returns 0 DateTime.Compare(DateTime.Now,DateTime.Parse(dateTime)) // returns 1 I need to compare 2 dates, using...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.