473,385 Members | 2,180 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,385 software developers and data experts.

date confusion

djc
I am confused with all the options for date values... What should I be using
when I want to compare (=, >, <) two dates, not including the time.. for
example when inserting data in a database the data may have the full date
and time like '12/15/2004 12:31:23 AM'. How do I convert that into just
'12/15/2004'? In other words I need to test if the current date is before or
after a stored date value, but the time does not matter.

any input is appreciated.
Nov 21 '05 #1
4 1148
"djc" <no***@nowhere.com> schrieb:
I am confused with all the options for date values... What should I be
using
when I want to compare (=, >, <) two dates, not including the time.. for
example when inserting data in a database the data may have the full date
and time like '12/15/2004 12:31:23 AM'. How do I convert that into just
'12/15/2004'? In other words I need to test if the current date is before
or
after a stored date value, but the time does not matter.


'If d1.Date = d2.Date Then...'.

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

Nov 21 '05 #2
djc,
Use DateTime.Date to get just the date part of a DateTime value.

Dim date1 As DateTime = #12/15/2004 12:31:23 AM#
Dim date2 As DateTime = #12/15/2004#

Debug.WriteLine(date1 = date2, "date1 = date2")
Debug.WriteLine(date1.Date = date2, "date1.Date = date2")

You can use DateTime.TimeOfDay to get just the time part of a DateTime
value.

Dim time1 As TimeSpan = #12:31:23 AM#.TimeOfDay

Debug.WriteLine(date1.TimeOfDay.Equals(time1), "date1 = time1")

Unfortunately the equal "=" operator is not overloaded to compare TimeSpan
values, we need to wait for VS.NET 2005 (aka Whidbey, due out later in 2005)
to allow overloading the equal operator.

' VS.NET 2005 syntax
Debug.WriteLine(date1.TimeOfDay = time1, "date1 = time1")

WARNING: Time values includes fractions of milliseconds, so be careful when
comparing them for equality (less or greater usually works better).

Hope this helps
Jay
"djc" <no***@nowhere.com> wrote in message
news:uC**************@tk2msftngp13.phx.gbl...
I am confused with all the options for date values... What should I be
using
when I want to compare (=, >, <) two dates, not including the time.. for
example when inserting data in a database the data may have the full date
and time like '12/15/2004 12:31:23 AM'. How do I convert that into just
'12/15/2004'? In other words I need to test if the current date is before
or
after a stored date value, but the time does not matter.

any input is appreciated.

Nov 21 '05 #3
djc
thanks

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:OF****************@TK2MSFTNGP14.phx.gbl...
"djc" <no***@nowhere.com> schrieb:
I am confused with all the options for date values... What should I be
using
when I want to compare (=, >, <) two dates, not including the time.. for
example when inserting data in a database the data may have the full date and time like '12/15/2004 12:31:23 AM'. How do I convert that into just
'12/15/2004'? In other words I need to test if the current date is before or
after a stored date value, but the time does not matter.


'If d1.Date = d2.Date Then...'.

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

Nov 21 '05 #4
djc
Thanks for the reply!

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
djc,
Use DateTime.Date to get just the date part of a DateTime value.

Dim date1 As DateTime = #12/15/2004 12:31:23 AM#
Dim date2 As DateTime = #12/15/2004#

Debug.WriteLine(date1 = date2, "date1 = date2")
Debug.WriteLine(date1.Date = date2, "date1.Date = date2")

You can use DateTime.TimeOfDay to get just the time part of a DateTime
value.

Dim time1 As TimeSpan = #12:31:23 AM#.TimeOfDay

Debug.WriteLine(date1.TimeOfDay.Equals(time1), "date1 = time1")

Unfortunately the equal "=" operator is not overloaded to compare TimeSpan
values, we need to wait for VS.NET 2005 (aka Whidbey, due out later in 2005) to allow overloading the equal operator.

' VS.NET 2005 syntax
Debug.WriteLine(date1.TimeOfDay = time1, "date1 = time1")

WARNING: Time values includes fractions of milliseconds, so be careful when comparing them for equality (less or greater usually works better).

Hope this helps
Jay
"djc" <no***@nowhere.com> wrote in message
news:uC**************@tk2msftngp13.phx.gbl...
I am confused with all the options for date values... What should I be
using
when I want to compare (=, >, <) two dates, not including the time.. for
example when inserting data in a database the data may have the full date and time like '12/15/2004 12:31:23 AM'. How do I convert that into just
'12/15/2004'? In other words I need to test if the current date is before or
after a stored date value, but the time does not matter.

any input is appreciated.


Nov 21 '05 #5

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

Similar topics

2
by: amith | last post by:
hi I have written javascript for comparing two dates in US format and finding out whether the start date is greater than the end date and vice versa. In this attempt i have instantiated the...
3
by: C White | last post by:
got another one for you guys out there, and thanks again for the help with my "counting question" this time i'm looking to select records based on date, the database stores the date as...
3
by: Dino | last post by:
I am creating a website that is going to ask the user to enter a date! then from an access database get all records where a date field is greater then the date entered! Sounds simple, I do it in...
7
by: Gertjan van Heijst | last post by:
Hi, I really hope someone can help me because I've already spend 2 days on this problem and I'm not getting anywhere. I think the problem is that I don't really understand how text boxes store...
7
by: Tony Williams | last post by:
I have a check box called Loadtxt and when it is ticked I want the value of a control called EmailDatetxt to be today's date. I am using this code in the AfterUpdate event of the checkbox but it...
3
by: Gerry Abbott | last post by:
Hi all Im in Ireland, so date format is always dd/mm/yy. It trying use query as a filter for a recordset, containing a date field, SELECT tblInspections.InspDate FROM tblInspections WHERE...
2
by: Bill | last post by:
Question: For a table like this: Date | Description | Amount | Balance 9/25/04 | payment on acct | 25.00 | 0.00 10/1/04 | delivery | 54.25 | 54.25 11/5/04 | payment on...
44
by: user | last post by:
Hi, Let's say I have 2 dates in the b/m format: Date 1 and date 2 How do I check whether Date2 is later than Date 1? Date1. 21-Nov-2006 09:00:00 PM
10
by: ARC | last post by:
Hello all, General question for back-end database that has numerous date fields where the database will be used in regions that put the month first, and regions that do not. Should I save a...
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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.