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

Dates mm/dd/yyyy & dd/mm/yyyy giving a major headache

Hi All

I am trying to query a database with a combination of surname and date of
birth but it is giving me wrong results in certain conditions.

It is the mm/dd/yyyy and dd/mm/yyyy stuff that is not making it work.

If I enter date like 25/12/1976 then it works fine as the date will not be
valid like 12/25/1976 and everything works fine and my query executes
properly.

However if I enter a date like 07/08/1976 (07-Aug-1976) it think the query
thinks I have entered 08/07/1976 (08-July-1976) and brings back the wrong
result.

Can some one please help.
I am using the code below

strDateofBirth = request.form("dd") & "/ & request.form("mm") & "/ &
request.form("yy")

MySql="select * from empprofile where lastname ='"&strSurname&"' and
dateofbirth = #" & strDateofBirth &"#"

RS.open MySql,conn

Jul 19 '05 #1
4 2452
J P Singh wrote:
Hi All

I am trying to query a database with a combination of surname and
date of birth but it is giving me wrong results in certain conditions.

It is the mm/dd/yyyy and dd/mm/yyyy stuff that is not making it work.

Searchwww.aspfaq.com for the keyword "dates". This is a VERY frequently
asked question :-)

Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jul 19 '05 #2
Unless your dates are held in the DB as strings (in which case you are going
to be doing a lot of hair pulling) you should always try and pass dates in
SQL statements as ISO format:

yyyymmdd hhnnss [All databases seem to like this]

or

yyyy-mm-dd hh:nn:ss [SQL Server doesn't like this when in non English / US
language mode: http://tinyurl.com/2x7sf]

since the ISO format cannot be misconstrued to be anything other than the
date intended.

http://www.4guysfromrolla.com/webtec...022202-1.shtml

If the dates *are* stored in strings then you obviously need to cast [read
'CAST' for SQL Server and whatever works for alternative databases) them as
datetime and compare against datetime in your SQL statement. However, you
may get incorrect results because of the possibility that the cast statement
may translate the date incorrectly (eg. dd/mm/yy read as mm/dd/yy).

http://www.aspfaq.com/2206

Chris.

"J P Singh" <noemail@asIhatespam> wrote in message
news:eh****************@tk2msftngp13.phx.gbl...
Hi All

I am trying to query a database with a combination of surname and date of
birth but it is giving me wrong results in certain conditions.

It is the mm/dd/yyyy and dd/mm/yyyy stuff that is not making it work.

If I enter date like 25/12/1976 then it works fine as the date will not be
valid like 12/25/1976 and everything works fine and my query executes
properly.

However if I enter a date like 07/08/1976 (07-Aug-1976) it think the query
thinks I have entered 08/07/1976 (08-July-1976) and brings back the wrong
result.

Can some one please help.
I am using the code below

strDateofBirth = request.form("dd") & "/ & request.form("mm") & "/ &
request.form("yy")

MySql="select * from empprofile where lastname ='"&strSurname&"' and
dateofbirth = #" & strDateofBirth &"#"

RS.open MySql,conn


Jul 19 '05 #3
> If I enter date like 25/12/1976

Why do people insist on using ambiguous date formats?
However if I enter a date like 07/08/1976
I don't know if that's July 8th or August 7th. How do you expect software
to?

Use a *STANDARD* format (that's why we have standards).

Ironically, the standard changes between products. For Access, the ONLY
safe date format is YYYY-MM-DD. (For SQL Server, it's YYYYMMDD.)
strDateofBirth = request.form("dd") & "/ & request.form("mm") & "/ &
request.form("yy")


So all you have to do is change the above to:

strDateofBirth = request.form("yy") & "-" & request.form("mm") & "-" &
request.form("dd")

Assuming, of course, that you've already validated that this creates a valid
date and that all three values are numbers and don't contain "danger"
characters like '

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
Jul 19 '05 #4
Thanks a lot everyone.
"Aaron Bertrand - MVP" <aa***@TRASHaspfaq.com> wrote in message
news:ua**************@TK2MSFTNGP12.phx.gbl...
If I enter date like 25/12/1976
Why do people insist on using ambiguous date formats?
However if I enter a date like 07/08/1976


I don't know if that's July 8th or August 7th. How do you expect software
to?

Use a *STANDARD* format (that's why we have standards).

Ironically, the standard changes between products. For Access, the ONLY
safe date format is YYYY-MM-DD. (For SQL Server, it's YYYYMMDD.)
strDateofBirth = request.form("dd") & "/ & request.form("mm") & "/ &
request.form("yy")


So all you have to do is change the above to:

strDateofBirth = request.form("yy") & "-" & request.form("mm") & "-" &
request.form("dd")

Assuming, of course, that you've already validated that this creates a

valid date and that all three values are numbers and don't contain "danger"
characters like '

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/

Jul 19 '05 #5

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

Similar topics

2
by: Adrian Parker | last post by:
I have a server app which is sent a date in the local format of the client machine. I've no control over the client app at all, so have to code at the server end to cope with any problems. The...
4
by: F | last post by:
Hi I have posted the question few days back about problem in inserting the dates in SQL server and thankful to them who replied. That was solved and this is a nice solution....
10
by: Colin Steadman | last post by:
I'm a stupid ASP programmer and I dont do Javascript (except for very simple tasks anyway), and I'm in a bit of a predicament. I've used a javascript table sorting script from here: ...
4
by: Richard Hollenbeck | last post by:
I'm trying to write some code that will convert any of the most popular standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan 1908) and compare the first with the second and...
22
by: mike | last post by:
If I had a date in the format "01-Jan-05" it does not sort properly with my sort routine: function compareDate(a,b) { var date_a = new Date(a); var date_b = new Date(b); if (date_a < date_b)...
36
by: Lindie | last post by:
The more I read the more confused I get. Too much on dates calulations in the groups. I need to know how often a book has been loaned out over the past year- 52 weeks. My table has Book...
1
by: Simone | last post by:
Is it possible to enable drag functionality for an object in a frame and then drop it in another frame? If yes, how? Thank you. Simone
10
by: John | last post by:
Hi I have a form with tow fields for dates in dd/mm/yyyy format. I am trying to use the fields in a query's where clause as below; "SELECT * " & _ "FROM Orders " & _ " WHERE Orders.)>= #" &...
1
by: sausthav | last post by:
Hi All, I am unable to get the excel open when user select two dates from my code. Previously i was successfully extracting values by selecting year and month values from the webpage. Could you help...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
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...
0
agi2029
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,...
0
isladogs
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...

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.