I need to compare two DateTime variables named as t1 and t2 using VB.NET
2003. If t1 is any earlier time as t2, only then program should do
something like...
If (t1 < t2) Then
'DoSomethingHer e...
End If
But I don't figue out how comparing DateTimes is working.
I tried to compare these variables with same time in Immediate-window...
?t1
#3/30/2005 10:18:14 AM#
?t2
#3/30/2005 10:18:14 AM#
?DateTime.Compa re(t1, t2)
1
?DateTime.Compa re(t2, t1)
-1
?t1.CompareTo(t 2)
1
?t1 = t2
False
?t1.Equals(t2)
False
....so why these t1 ja t2 variables content is not same in this case
according comparing results !?!
--
Thanks in advance!
Mika 4 7337
Mika,
I find the most easy one to compare the ticks
if t1.Ticks < t2.Ticks then
(the bracket is not needed in VBNet)
I hope this helps,
Cor
> I find the most easy one to compare the ticks
if t1.Ticks < t2.Ticks then
Thanks Cor! This is what I needed.
(the bracket is not needed in VBNet)
I know, but sometimes I use C#, and in my mind brackets make it more
readable - so is there any reasons as an example why I should't use
brackets with VB.NET where brackets are not needed?
Mika, I know, but sometimes I use C#, and in my mind brackets make it more readable - so is there any reasons as an example why I should't use brackets with VB.NET where brackets are not needed?
I find it just not looking good. For me it tells that there is something
extra with the evaluated expression. While that is not in your case.
However, probably just a matter of preference. Therefore do it as you wish.
Cor
On Thu, 12 May 2005 09:28:53 +0300, Mika M
<mahmik_nospam@ removethis_luuk ku.com> wrote: I need to compare two DateTime variables named as t1 and t2 using VB.NET 2003. If t1 is any earlier time as t2, only then program should do something like...
If (t1 < t2) Then 'DoSomethingHer e... End If
But I don't figue out how comparing DateTimes is working.
I tried to compare these variables with same time in Immediate-window...
Are you certain they were the same (milliseconds and ticks, not just the
formatted string)?
I'm using > and < operators directly on dates all the time.
Try this code:
Dim d1, d2 As Date
Dim dt1, dt2 As DateTime
d1 = Now
d2 = d1
dt1 = d1
dt2 = d1
Debug.WriteLine ((d1 < d2) & ", " & (d1 = d2) & ", " & (d1 > d2))
Debug.WriteLine ((dt1 < dt2) & ", " & (dt1 = dt2) & ", " & (dt1 > dt2))
d2 = d2.AddMilliseco nds(1)
dt2 = d2
Debug.WriteLine ((d1 < d2) & ", " & (d1 = d2) & ", " & (d1 > d2))
Debug.WriteLine ((dt1 < dt2) & ", " & (dt1 = dt2) & ", " & (dt1 > dt2))
Result:
False, True, False
False, True, False
True, False, False
True, False, False This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Donnal Walter |
last post by:
I was very surprised to discover that
>>> import datetime
>>> x = datetime.date(2004, 9, 14)
>>> y = datetime.datetime(2004, 9, 14, 6, 43, 15)
>>> print x == y
True
How can these two objects be considered equal? Is there a *general* way
to test for date != datetime as well as 4.5 != 4.6?
|
by: Manny Chohan |
last post by:
Hi, i have two datetime values in format 11/22/04 9:00 AM and 11/22/04 9:30
AM. How can i compare dates .net c# or if there is any other way such as
Javascript.
Thanks
Manny
|
by: scorpion53061 |
last post by:
What I thought would be pretty easy has turned out not to be.
I have three variables. Actiontime is formatted as 08/11/2004 11:03PM
Actiontime
JobStreamStart (11:00:00PM)
JobStreamEnd (2:00:00AM)
If (Format(CDate(ActionTime), "t") >= JobStreamStart AND
(Format(CDate(ActionTime), "t") < jobstreamend Then
|
by: Mike Collins |
last post by:
I cannot get the correct drop down list value from a drop down I have on my
web form. I get the initial value that was loaded in the list.
It was asked by someone else what the autopostback was set to...it is set to
false.
Can someone show me what I am doing wrong and tell me the correct way? Thank
you.
In the page load event, I am doing the following:
|
by: Jim Armstrong |
last post by:
Hi all -
This problem has been driving me crazy, and I'm hoping the answer is
something stupid I am neglecting to see....
The procedure posted below is part of an Access/SQL database I have
developed. Basically, the user would input a beginning and ending date,
and the query goes and pulls records that meet the following criteria:
1. TradeDate is between beginning date and ending date
| |
by: sherifffruitfly |
last post by:
Hi all,
The following function is the ValueChanged handler for two
DateTimePicker thingies - allowing the user to specify a date range. I
don't understand why the following bug exists: when the first picker is
set later than the second, the messagebox pops up *twice* in
succession.
What's causing that? How can I achieve the (obvious) desired effect?
|
by: Bob |
last post by:
Hi,
I have a wrong result when testing today against a date fetched from a table
in excel.
The value in excel is: 14/12/2006 (european format).
When today is after that value in excel, the message "time is over" must
appear, otherwise nothing.
My problem is that the message appear already when today = that value.
Any idea why?
|
by: kyosohma |
last post by:
Hi,
I am writing a reminder program for our Zimbra email client. One of
the requirements I was given was to automatically increment or
decrement the display to show something like the following:
5 minutes until appointment
or
|
by: =?Utf-8?B?UGF1bA==?= |
last post by:
Hi I am trying to compare just the time portion of two variables that are of
date time part. For example I have
dtdate1= 2/2/07 10:00:00
dtdate2=3/4/07 9:00:00
so for the comparision I would want 10:00:00 cmp with 9:00:00
so ddate1>ddate2 is true.
I tried converting to short time string but the comparison can not be done
on the strings.
Thanks Paul.
--
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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...
| |