Oct 31st, 2002, 08:33 PM
#1
Thread Starter
Lively Member
Compare Time in text
How do I compare Timings like "06:00 AM is earlier than 05:30 AM"??
An elephant learning VB..
Oct 31st, 2002, 08:52 PM
#2
PowerPoster
Here is one way:
Code:
using System;
public class TimeExample
{
public static void Main()
{
DateTime tOne = DateTime.Now;
DateTime tTwo = DateTime.Now.AddHours(2);
if (tOne > tTwo)
{
Console.WriteLine("tOne is greater than tTwo");
}
else
{
Console.WriteLine("tTwo is greater than tOne");
}
}
}
Oct 31st, 2002, 08:56 PM
#3
PowerPoster
Or..
Code:
using System;
public class TimeExample
{
public static void Main()
{
DateTime tOne = DateTime.Now;
DateTime tTwo = DateTime.Now.AddHours(2);
switch (tOne.CompareTo(tTwo))
{
case -1:
Console.WriteLine("tOne is less than tTwo");
break;
case 0:
Console.WriteLine("tOne is equal to tTwo");
break;
case 1:
Console.WriteLine("tOne is greater than tTwo");
break;
}
}
}
Oct 31st, 2002, 10:32 PM
#4
Addicted Member
Dang! You beat me to it you weenie! I'll post this example anyway.
Furry
Eat long and prosper!
If someone helps you, find someone you can help.
If you still have time, click on the darn banner up there and help the forum!
Oct 31st, 2002, 10:32 PM
#5
Addicted Member
Oops forgot the attachment. I hate when I do that...
Attached Files
Eat long and prosper!
If someone helps you, find someone you can help.
If you still have time, click on the darn banner up there and help the forum!
Oct 31st, 2002, 10:46 PM
#6
PowerPoster
lol.....well, if you weren't so fat and furry you might have beet me 2 it...
Oct 31st, 2002, 10:49 PM
#7
Addicted Member
LOL actually, I'm really not Fat_N_Furry. My cat is. He weighs 20 pounds, for crying out loud! I'm Skinny_N_Hairless. LOL
I think my example's better, though.
Eat long and prosper!
If someone helps you, find someone you can help.
If you still have time, click on the darn banner up there and help the forum!
Oct 31st, 2002, 10:58 PM
#8
PowerPoster
He stated that he wants to compare times. All you're example does is perform arithmetic operations. Big difference...
Nov 1st, 2002, 11:26 AM
#9
Addicted Member
But that IS coparing times, isn't it? It's comparing the current time to the entered time!
...For some reason that embarrassed smiley doesn't really look all that embarrased to me...
Eat long and prosper!
If someone helps you, find someone you can help.
If you still have time, click on the darn banner up there and help the forum!
Nov 1st, 2002, 12:57 PM
#10
PowerPoster
For one, your example doesn't take into consideration AM or PM.
Nov 1st, 2002, 01:56 PM
#11
Addicted Member
Does yours? I apologize for my ignorance, but I don't really quite understand your code...
Eat long and prosper!
If someone helps you, find someone you can help.
If you still have time, click on the darn banner up there and help the forum!
Nov 1st, 2002, 02:05 PM
#12
PowerPoster
Yes, b/c we are using DateTime objects, not just integers. These are two seperate datatypes. They are optimized to work with real date and time data.
Nov 1st, 2002, 02:07 PM
#13
Addicted Member
Oh. I didn't know that. Thanks for the info.
Eat long and prosper!
If someone helps you, find someone you can help.
If you still have time, click on the darn banner up there and help the forum!
Nov 1st, 2002, 02:12 PM
#14
Maybe the VB.NEt version would help:
VB Code:
Dim tOne As DateTime = DateTime.Now
Dim tTwo As DateTime = DateTime.Now.AddHours(2)
Select Case tOne.CompareTo(tTwo)
Case -1
MsgBox("tOne is less than tTwo")
Case 0
MsgBox("tOne is equal to tTwo")
Case 1
MsgBox("tOne is greater than tTwo")
End Select
Nov 1st, 2002, 02:24 PM
#15
PowerPoster
That's my fault. I keep forgetting I'm posting C# code instead of vb.net.
Nov 1st, 2002, 03:05 PM
#16
Its my personal opinion that everyone should at know how to translate back and forth (C# <-> V.NET) so maybe that will encourage people. Of course I guess I messed it up then, but hey.
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