473,769 Members | 2,062 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("d d") & "/ & request.form("m m") & "/ &
request.form("y y")

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

RS.open MySql,conn

Jul 19 '05 #1
4 2479
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.aspfa q.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@asIhat espam> wrote in message
news:eh******** ********@tk2msf tngp13.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("d d") & "/ & request.form("m m") & "/ &
request.form("y y")

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("d d") & "/ & request.form("m m") & "/ &
request.form("y y")


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

strDateofBirth = request.form("y y") & "-" & request.form("m m") & "-" &
request.form("d d")

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***@TRASHasp faq.com> wrote in message
news:ua******** ******@TK2MSFTN GP12.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("d d") & "/ & request.form("m m") & "/ &
request.form("y y")


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

strDateofBirth = request.form("y y") & "-" & request.form("m m") & "-" &
request.form("d d")

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
1773
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 server is in the US, so any dates need to be in US format before they will convert using strtotime() Here is what i'm doing at the moment.. // need to convert date to use USA mm/dd/yyyy format on server // $lt contains the date in the client...
4
2412
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. http://www.aspfaq.com/show.asp?id=2023 Now I am facing another problem. I have to get data between two dates. That dates user has to provide and in
10
3296
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: http://www.ipwebdesign.net/kaelisSpace/useful_tableSort.html This works great except it doesn't sort my UK formatted dates properly, and I end up with something like this: Birth Date (dd/mm/yyyy)
4
5390
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 calculate days, months, and years. This is not for a college course. It's for my own personal genealogy website. I'm stumped about the code. I'm working on it but not making much progress. Is there any free code available anywhere? I know it...
22
4168
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) { return -1; } else
36
2079
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 DateOut Total
1
1391
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
9904
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.)>= #" & Format(!!, "dd/mm/yyyy") & "# And Orders.<= #" & Format(!!, "dd/mm/yyyy") & "# "
1
4060
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 me out in writing the Access 2003 SQL query to resolve my issue. Looking forward to your help and support:) I am giving the snapshot of my code: <%@Language=VBScript%> <% Dim TmplXls Dim DestXls Dim DB
0
9589
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10215
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9996
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8872
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7410
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5307
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3964
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.