473,657 Members | 2,395 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2004
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.n et.au> schreef in bericht
news:ee******** *****@TK2MSFTNG P10.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.n et.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:3 0: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.n et.au> wrote in message
news:ee******** *****@TK2MSFTNG P10.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
1865
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 comparison is being run on one server between to databases. It has been run several times but each time we get that error message, the table ID number tends to change each time. We also had a problem before where the 'TEMPDB' did not have enough...
4
2628
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 in which file-1 resides (in OS) and I have stored the UTC of the file's modified time in the database. 2. Next I create a zip archive and send the file to US, where it's
1
1937
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 compare two dates? Thanks Manny
5
6329
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 uniqueidentifier, originally taken from objectGUID from active directory domain)
12
29445
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 follows: function doDateCheckNow(source, args) { var oDate = document.getElementById(source.controltovalidate); // dd/mm/yyyy
3
1944
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 is taking time, Any insights to this? Thanks in Advance thomson
4
24875
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 standard library to do this? I'm not interested in Boost until it becomes part of the standard.
1
4106
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 example is as follows: Patsy would like to volunteer time at a booth this year at the fair. Her optimal timeframe to volunteer is between 1:00pm and 5:00pm and she inputs this via some form. Let's say that I want to compare this to a...
1
2546
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 available, but each of them should be compared with "accounts_log". Lests say a one of the accid chose is A1, then take users IP and current time - time(). now compare A1 exists in "accounts_log" with the ip, this can exist multiple times but pick one...
3
2727
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 the second format, and I dont understand why it isnt returning 0 Thank you
0
8310
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8732
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...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6166
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
4155
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...
0
4306
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1955
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1615
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.