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

Searching by DATE problem

les
I have a form to search records by date of birth. The form has 3
dropdowns for day, month and year:

Dim strDOB as string = ("'" & dobday.selectedvalue & " " &
dobmonth.selectedvalue & " " & dobyear.selectedvalue & "'")

strDOB=DateTime.Parse(strDOB)

strSQL = "SELECT * FROM table1 where dob='" & strDOB & "' "

When i response.write the original string I get '04 March 1951'
When i response.write(strDOB) it gives me 04/03/1951 but the records
returned are those with the DOB: 03/04/1951.

If I select a day over 12 it gives the error:
The conversion of a char data type to a datetime data type resulted in
an out-of-range datetime value.

Presumably I need to format strDOB as UK date format eg: 25/12/1951,
but I've tried various things and no success. Can anyone help please?

Thanks
Leslie
Nov 18 '05 #1
4 1109

<les> wrote in message news:89********************************@4ax.com...
I have a form to search records by date of birth. The form has 3
dropdowns for day, month and year:

Dim strDOB as string = ("'" & dobday.selectedvalue & " " &
dobmonth.selectedvalue & " " & dobyear.selectedvalue & "'")

strDOB=DateTime.Parse(strDOB)

strSQL = "SELECT * FROM table1 where dob='" & strDOB & "' "

When i response.write the original string I get '04 March 1951'
When i response.write(strDOB) it gives me 04/03/1951 but the records
returned are those with the DOB: 03/04/1951.

If I select a day over 12 it gives the error:
The conversion of a char data type to a datetime data type resulted in
an out-of-range datetime value.

Presumably I need to format strDOB as UK date format eg: 25/12/1951,
but I've tried various things and no success. Can anyone help please?

Thanks
Leslie


A few notes:

1) DateTime has a constructor that uses separate year, month and day values.
This is
more direct than first building a string and then parsing it (and
assigning that DateTime
value to the same string??)

2) look into "parameters" for your query: then you can supply the real
DateTime value
without having to build-and-parse a string in the query (with all the
"MDY" vs. "DMY"
problems)

3) DateTime has a "ToString()" method that accepts a format parameter.
"dd/MM/yyyy"
should output the dateformat you want.

Hans Kesting
Nov 18 '05 #2
les
Thanks Hans,
But how would I apply "ToString()" in this case?
On Tue, 30 Dec 2003 09:45:14 +0100, "Hans Kesting"
<ne***********@spamgourmet.com> wrote:

<les> wrote in message news:89********************************@4ax.com...
I have a form to search records by date of birth. The form has 3
dropdowns for day, month and year:

Dim strDOB as string = ("'" & dobday.selectedvalue & " " &
dobmonth.selectedvalue & " " & dobyear.selectedvalue & "'")

strDOB=DateTime.Parse(strDOB)

strSQL = "SELECT * FROM table1 where dob='" & strDOB & "' "

When i response.write the original string I get '04 March 1951'
When i response.write(strDOB) it gives me 04/03/1951 but the records
returned are those with the DOB: 03/04/1951.

If I select a day over 12 it gives the error:
The conversion of a char data type to a datetime data type resulted in
an out-of-range datetime value.

Presumably I need to format strDOB as UK date format eg: 25/12/1951,
but I've tried various things and no success. Can anyone help please?

Thanks
Leslie


A few notes:

1) DateTime has a constructor that uses separate year, month and day values.
This is
more direct than first building a string and then parsing it (and
assigning that DateTime
value to the same string??)

2) look into "parameters" for your query: then you can supply the real
DateTime value
without having to build-and-parse a string in the query (with all the
"MDY" vs. "DMY"
problems)

3) DateTime has a "ToString()" method that accepts a format parameter.
"dd/MM/yyyy"
should output the dateformat you want.

Hans Kesting


Nov 18 '05 #3
les
Also, I thought I needed to convert the string to a date, so I don't
see why I would be using "tostring" for that
On Tue, 30 Dec 2003 10:25:17 +0000, les wrote:
Thanks Hans,
But how would I apply "ToString()" in this case?
On Tue, 30 Dec 2003 09:45:14 +0100, "Hans Kesting"
<ne***********@spamgourmet.com> wrote:

<les> wrote in message news:89********************************@4ax.com...
I have a form to search records by date of birth. The form has 3
dropdowns for day, month and year:

Dim strDOB as string = ("'" & dobday.selectedvalue & " " &
dobmonth.selectedvalue & " " & dobyear.selectedvalue & "'")

strDOB=DateTime.Parse(strDOB)

strSQL = "SELECT * FROM table1 where dob='" & strDOB & "' "

When i response.write the original string I get '04 March 1951'
When i response.write(strDOB) it gives me 04/03/1951 but the records
returned are those with the DOB: 03/04/1951.

If I select a day over 12 it gives the error:
The conversion of a char data type to a datetime data type resulted in
an out-of-range datetime value.

Presumably I need to format strDOB as UK date format eg: 25/12/1951,
but I've tried various things and no success. Can anyone help please?

Thanks
Leslie


A few notes:

1) DateTime has a constructor that uses separate year, month and day values.
This is
more direct than first building a string and then parsing it (and
assigning that DateTime
value to the same string??)

2) look into "parameters" for your query: then you can supply the real
DateTime value
without having to build-and-parse a string in the query (with all the
"MDY" vs. "DMY"
problems)

3) DateTime has a "ToString()" method that accepts a format parameter.
"dd/MM/yyyy"
should output the dateformat you want.

Hans Kesting


Nov 18 '05 #4
les
I have managed to fix it (finally!) using this:

SELECT * FROM table1 where Convert(char(10), DOB, 103) = '" & strDOB &
"'

Leslie
On Tue, 30 Dec 2003 12:29:07 GMT, le*@asasdad.com (les) wrote:
Also, I thought I needed to convert the string to a date, so I don't
see why I would be using "tostring" for that
On Tue, 30 Dec 2003 10:25:17 +0000, les wrote:
Thanks Hans,
But how would I apply "ToString()" in this case?
On Tue, 30 Dec 2003 09:45:14 +0100, "Hans Kesting"
<ne***********@spamgourmet.com> wrote:

<les> wrote in message news:89********************************@4ax.com...
I have a form to search records by date of birth. The form has 3
dropdowns for day, month and year:

Dim strDOB as string = ("'" & dobday.selectedvalue & " " &
dobmonth.selectedvalue & " " & dobyear.selectedvalue & "'")

strDOB=DateTime.Parse(strDOB)

strSQL = "SELECT * FROM table1 where dob='" & strDOB & "' "

When i response.write the original string I get '04 March 1951'
When i response.write(strDOB) it gives me 04/03/1951 but the records
returned are those with the DOB: 03/04/1951.

If I select a day over 12 it gives the error:
The conversion of a char data type to a datetime data type resulted in
an out-of-range datetime value.

Presumably I need to format strDOB as UK date format eg: 25/12/1951,
but I've tried various things and no success. Can anyone help please?

Thanks
Leslie

A few notes:

1) DateTime has a constructor that uses separate year, month and day values.
This is
more direct than first building a string and then parsing it (and
assigning that DateTime
value to the same string??)

2) look into "parameters" for your query: then you can supply the real
DateTime value
without having to build-and-parse a string in the query (with all the
"MDY" vs. "DMY"
problems)

3) DateTime has a "ToString()" method that accepts a format parameter.
"dd/MM/yyyy"
should output the dateformat you want.

Hans Kesting


Nov 18 '05 #5

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

Similar topics

1
by: Saso Zagoranski | last post by:
Hi! This is not exactly a C# question but I don't know where else to post it... I'm making an application where the user keeps track of it's art collection... I'm also trying to implement a...
5
by: justobservant | last post by:
When more than one keyword is typed into a search-query, most of the search-results displayed indicate specified keywords scattered throughout an entire website of content i.e., this is shown as...
7
by: evilcowstare via AccessMonster.com | last post by:
Hi, I have searched the forum for answers on this and to be honest as a novice I find it a bit confusing so apologies if it is simple. There are some searches that I want to apply to my database....
3
by: Aaron | last post by:
I'm trying to parse a table on a webpage to pull down some data I need. The page is based off of information entered into a form. when you submit the data from the form it displays a...
0
by: Kassimu | last post by:
Hi guys out there, There is this database Iam creating, I have a table with 40 fields among which there are Date/time, Text, Number, Memo and Yes/No fields and I have created the form bound to that...
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: 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?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
Oralloy
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,...
0
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...
0
tracyyun
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...

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.