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

comparing just the time portion of time date variables

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.
--
Paul G
Software engineer.
Jan 7 '08 #1
6 2568
On Mon, 07 Jan 2008 10:49:00 -0800, Paul <Pa**@discussions.microsoft.com
wrote:
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.
Depending on the formatting you use, you should be able to compare them as
strings.

However, I think it would be simpler to just use the DateTime.TimeOfDay
property. Get the value of that property from each DateTime instance and
compare the two.

Pete
Jan 7 '08 #2
thanks for the response, will give that a try. The short time string worked
for == comparisons but not or <. I ended up using additional variables and
just took the the short time string of both and copied the data into date
time variables which ends up using the current day for the missing day
portion of the variable. Sounds like the time of day will be easier and will
not have to use extra variables.
--
Paul G
Software engineer.
"Peter Duniho" wrote:
On Mon, 07 Jan 2008 10:49:00 -0800, Paul <Pa**@discussions.microsoft.com>
wrote:
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.

Depending on the formatting you use, you should be able to compare them as
strings.

However, I think it would be simpler to just use the DateTime.TimeOfDay
property. Get the value of that property from each DateTime instance and
compare the two.

Pete
Jan 7 '08 #3
Hi,

IT can be as easy as getting the timespan from the start of the day:

TimeSpan ts1 = dtdate1.Substract( dtdate1.Today);
TimeSpan ts2 = dtdate2.Substract( dtdate1.Today);

Now you can compare them. as either numeric (Total(Minutes/second, etc) )

--
Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.
"Paul" <Pa**@discussions.microsoft.comwrote in message
news:D6**********************************@microsof t.com...
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.
--
Paul G
Software engineer.

Jan 7 '08 #4
looks easy to impliment! Thanks for the additional information.
--
Paul G
Software engineer.
"Ignacio Machin ( .NET/ C# MVP )" wrote:
Hi,

IT can be as easy as getting the timespan from the start of the day:

TimeSpan ts1 = dtdate1.Substract( dtdate1.Today);
TimeSpan ts2 = dtdate2.Substract( dtdate1.Today);

Now you can compare them. as either numeric (Total(Minutes/second, etc) )

--
Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.
"Paul" <Pa**@discussions.microsoft.comwrote in message
news:D6**********************************@microsof t.com...
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.
--
Paul G
Software engineer.


Jan 7 '08 #5
Um, or you could just really use the TimeOfDay property, like Peter
said:

TimeSpan ts1 = dtdate1.TimeOfDay;
TimeSpan ts2 = dtdate2.TimeOfDay;

And then compare those. No need to perform an extra operation when the
logic is encapsulated for you already.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Paul" <Pa**@discussions.microsoft.comwrote in message
news:99**********************************@microsof t.com...
looks easy to impliment! Thanks for the additional information.
--
Paul G
Software engineer.
"Ignacio Machin ( .NET/ C# MVP )" wrote:
>Hi,

IT can be as easy as getting the timespan from the start of the day:

TimeSpan ts1 = dtdate1.Substract( dtdate1.Today);
TimeSpan ts2 = dtdate2.Substract( dtdate1.Today);

Now you can compare them. as either numeric (Total(Minutes/second,
tc) )

--
Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.
"Paul" <Pa**@discussions.microsoft.comwrote in message
news:D6**********************************@microso ft.com...
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.
--
Paul G
Software engineer.



Jan 7 '08 #6
Ended up just using the time span time of day as Pete suggested, got rid of
some extra variables as well!
--
Paul G
Software engineer.
"Nicholas Paldino [.NET/C# MVP]" wrote:
Um, or you could just really use the TimeOfDay property, like Peter
said:

TimeSpan ts1 = dtdate1.TimeOfDay;
TimeSpan ts2 = dtdate2.TimeOfDay;

And then compare those. No need to perform an extra operation when the
logic is encapsulated for you already.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Paul" <Pa**@discussions.microsoft.comwrote in message
news:99**********************************@microsof t.com...
looks easy to impliment! Thanks for the additional information.
--
Paul G
Software engineer.
"Ignacio Machin ( .NET/ C# MVP )" wrote:
Hi,

IT can be as easy as getting the timespan from the start of the day:

TimeSpan ts1 = dtdate1.Substract( dtdate1.Today);
TimeSpan ts2 = dtdate2.Substract( dtdate1.Today);

Now you can compare them. as either numeric (Total(Minutes/second,
tc) )

--
Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.
"Paul" <Pa**@discussions.microsoft.comwrote in message
news:D6**********************************@microsof t.com...
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.
--
Paul G
Software engineer.


Jan 7 '08 #7

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

Similar topics

6
by: teddysnips | last post by:
I have a table called WorkItem. It models a chunk of work done during a working day. It has two columns that I'm interested in: Start (smalldatetime) - the TIME the work block is begun...
2
by: Philip Townsend | last post by:
I am having difficulty with a simple routine as follows: public static bool VerifyExpirationDate(DateTime date) { if(date>=DateTime.Now)return true; else return false; } The problem is that...
4
by: Mika M | last post by:
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...
5
by: JL | last post by:
I need to compare two times. The problem I have is this: In my code I create a time variable using the format statement below: dim firstTime as DateTime fistTime = Format("12:00:00 AM", "T") ...
5
by: rs | last post by:
I have a table with a timestamp field which contains the date and time. ie. 9/13/2004 9:10:00 AM. I would like to split this field into 2 fields, one with just the DATE portion ie 9/13/2004 and...
5
by: Kermit Piper | last post by:
Hello, I am comparing two date values, one from a database and one that has been converted from a hard-coded string into an actual Date type. So far so good. The problem I'm having is that one...
2
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...
2
by: Pugi! | last post by:
hi, I am using this code for checking wether a value (form input) is an integer and wether it is smaller than a given maximum and greater then a given minimum value: function...
4
by: anagai | last post by:
I just want to check if a date entered in a textbox is equal to the current system date. I set the date object from the input field like this: dt1=new Date('10/01/2007'); the current system...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.