473,785 Members | 2,372 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dates in where clause

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.[Delivery Date])>= #" & Format([Forms]![Batch
Invoices]![FromDate], "dd/mm/yyyy") & "# And Orders.[Delivery Date]<= #" &
Format([Forms]![Batch Invoices]![ToDate], "dd/mm/yyyy") & "# "

My problem is that query doe snot read the dates correctly and rather takes
them as in mm/dd/yyyy format i.e. if 01/07/2006 (dd/mm/yyyy) was entered,
query brings records for 07/01/2006 (mm/dd/yyyy).

What is the ideal way to deal with the dates in this case so the dates are
taken as dd/mm/yyyy by the query?

Thanks

Regards
Jul 12 '06 #1
10 9904
format them in mm-dd-yyyy format.

Jul 13 '06 #2
Where? How should I modify the where clause? I can't expect the user to
enter date in non-dd/mm/yyyy format as they are all used to it due to the
locale.

Thanks

Regards
<pi********@hot mail.comwrote in message
news:11******** **************@ m73g2000cwd.goo glegroups.com.. .
format them in mm-dd-yyyy format.

Jul 13 '06 #3
* John:
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.[Delivery Date])>= #" & Format([Forms]![Batch
Invoices]![FromDate], "dd/mm/yyyy") & "# And Orders.[Delivery Date]<= #" &
Format([Forms]![Batch Invoices]![ToDate], "dd/mm/yyyy") & "# "

My problem is that query doe snot read the dates correctly and rather takes
them as in mm/dd/yyyy format i.e. if 01/07/2006 (dd/mm/yyyy) was entered,
query brings records for 07/01/2006 (mm/dd/yyyy).

What is the ideal way to deal with the dates in this case so the dates are
taken as dd/mm/yyyy by the query?

Thanks

Regards

Are the controls bound? If so, are the fields they're bound to
Date/Time fields or Text fields?

--
Randy Harris
tech at promail dot com
I'm pretty sure I know everything that I can remember.
Jul 13 '06 #4
Controls are not bound, they are just for user to enter date criteria for
query to pick up records for.

Thanks

Regards

"Randy Harris" <pl****@send.no .spamwrote in message
news:EV******** ************@ne wssvr29.news.pr odigy.net...
>* John:
>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.[Delivery Date])>= #" & Format([Forms]![Batch
Invoices]![FromDate], "dd/mm/yyyy") & "# And Orders.[Delivery Date]<= #"
& Format([Forms]![Batch Invoices]![ToDate], "dd/mm/yyyy") & "# "

My problem is that query doe snot read the dates correctly and rather
takes them as in mm/dd/yyyy format i.e. if 01/07/2006 (dd/mm/yyyy) was
entered, query brings records for 07/01/2006 (mm/dd/yyyy).

What is the ideal way to deal with the dates in this case so the dates
are taken as dd/mm/yyyy by the query?

Thanks

Regards

Are the controls bound? If so, are the fields they're bound to Date/Time
fields or Text fields?

--
Randy Harris
tech at promail dot com
I'm pretty sure I know everything that I can remember.

Jul 13 '06 #5

John wrote:
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.[Delivery Date])>= #" & Format([Forms]![Batch
Invoices]![FromDate], "dd/mm/yyyy") & "# And Orders.[Delivery Date]<= #" &
Format([Forms]![Batch Invoices]![ToDate], "dd/mm/yyyy") & "# "

My problem is that query doe snot read the dates correctly and rather takes
them as in mm/dd/yyyy format i.e. if 01/07/2006 (dd/mm/yyyy) was entered,
query brings records for 07/01/2006 (mm/dd/yyyy).

What is the ideal way to deal with the dates in this case so the dates are
taken as dd/mm/yyyy by the query?

Thanks

Regards
If I had to deal with this I would ... probably ... maybe ... create a
public function that translated 12/07/2006 to #07/12/2006#.

Here is an example (there are many ways of doing this).

Public Function SQLStringFromDD MMYYYY(ByVal DDMMYYYY As String) As
String
Dim aOldParts() As String
Dim aNewParts(0 To 2) As String
aOldParts = Split(DDMMYYYY, "/")
aNewParts(0) = aOldParts(1)
aNewParts(1) = aOldParts(0)
aNewParts(2) = aOldParts(2)
SQLStringFromDD MMYYYY = _
"#" & Join(aNewParts, "/") & "#"
End Function

Then I would use the function to create my SQL as:

"SELECT * " & _
"FROM Orders " & _
" WHERE Orders.[Delivery Date])>=" _
& SQLStringFromDD MMYYYY([Forms]![Batch Invoices]![FromDate]) _
& " Orders.[Delivery Date]<=" _
SQLStringFromDD MMYYYY([Forms]![Batch Invoices]![ToDate])

If the Batch Invoices Form had a module I would modify this slightly to
"SELECT * " & _
"FROM Orders " & _
" WHERE Orders.[Delivery Date])>=" _
& SQLStringFromDD MMYYYY(Form_Bat ch_Invoices.Fro mDate) _
& " Orders.[Delivery Date]<=" _
SQLStringFromDD MMYYYY(Form_Bat ch_Invoices.ToD ate)

or if the code is run in the form module to
"SELECT * " & _
"FROM Orders " & _
" WHERE Orders.[Delivery Date])>=" _
& SQLStringFromDD MMYYYY(Me.FromD ate) _
& " Orders.[Delivery Date]<=" _
SQLStringFromDD MMYYYY(Me.ToDat e)

or

"SELECT * " & _
"FROM Orders " & _
" WHERE Orders.[Delivery Date])>=" _
& SQLStringFromDD MMYYYY(FromDate ) _
& " Orders.[Delivery Date]<=" _
SQLStringFromDD MMYYYY(ToDate)

This all assumes you are using Access >= 2000 and that FromDate and
ToDate are strings in the format dd/mm/yyyy

Actually I wouldn't do this at all. I would provide the users with some
sort of calendar or drop down to choose the date ... but that is
another story.

As I just typed the SQL there may be syntax errors of course. The
function !!!!should!!!! be OK.

Jul 13 '06 #6
"John" wrote
Where? How should I modify the where clause?
I can't expect the user to enter date in non-dd/mm/yyyy
format as they are all used to it due to the locale.
In the same code where you build the Query, use the various Date functions,
e.g., DatePart, to modify the dates entered by the users to U.S. date
format. Frustrating, perhaps, but that's the way Jet SQL works.

Larry Linson
Microsoft Access MVP
Jul 13 '06 #7
* John:
Controls are not bound, they are just for user to enter date criteria for
query to pick up records for.

Thanks

Regards

"Randy Harris" <pl****@send.no .spamwrote in message
news:EV******** ************@ne wssvr29.news.pr odigy.net...
>* John:
>>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.[Delivery Date])>= #" & Format([Forms]![Batch
Invoices]![FromDate], "dd/mm/yyyy") & "# And Orders.[Delivery Date]<= #"
& Format([Forms]![Batch Invoices]![ToDate], "dd/mm/yyyy") & "# "

My problem is that query doe snot read the dates correctly and rather
takes them as in mm/dd/yyyy format i.e. if 01/07/2006 (dd/mm/yyyy) was
entered, query brings records for 07/01/2006 (mm/dd/yyyy).

What is the ideal way to deal with the dates in this case so the dates
are taken as dd/mm/yyyy by the query?

Thanks

Regards
Are the controls bound? If so, are the fields they're bound to Date/Time
fields or Text fields?

--
Randy Harris
tech at promail dot com
I'm pretty sure I know everything that I can remember.

In that case the data is strictly text. It might look like a date but
to Access it's not. The Format function is not going to be of any help
to you.

You'll need to write your own code to rearrange the text into something
Access will correctly interpret as a date.

Something along the lines of this:

Public Function FixDate(strDate As String)
Dim D1 As Integer, D2 As Integer
D1 = InStr(strDate, "/")
D2 = InStr(D1 + 1, strDate, "/")
FixDate = CDate(Mid(strDa te, D1 + 1, D2 - (D1 + 1)) & "/" _
& Left(strDate, D1 - 1) & "/" _
& Mid(strDate, D2 + 1))
End Function
--
Randy Harris
tech at promail dot com
I'm pretty sure I know everything that I can remember.
Jul 13 '06 #8
Try this syntax for your query:
"SELECT * " & _
"FROM Orders " & _
"WHERE Orders.[Delivery Date])>= #" & _
Format(CDate([Forms]![Batch Invoices]![FromDate]), "yyyy/mm/dd") & "# "
& _
"And Orders.[Delivery Date]<= #" &
Format(CDate([Forms]![Batch Invoices]![ToDate]), "yyyy/mm/dd") & "# "

Jul 13 '06 #9
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.[Delivery Date])>= #" & Format([Forms]![Batch
Invoices]![FromDate], "dd/mm/yyyy") & "# And Orders.[Delivery Date]<=
#" & Format([Forms]![Batch Invoices]![ToDate], "dd/mm/yyyy") & "# "

My problem is that query doe snot read the dates correctly and rather
takes them as in mm/dd/yyyy format i.e. if 01/07/2006 (dd/mm/yyyy)
was entered, query brings records for 07/01/2006 (mm/dd/yyyy).

What is the ideal way to deal with the dates in this case so the
dates are taken as dd/mm/yyyy by the query?

Thanks

Regards
When "speaking" with the Jet engine through dynamic SQL, Jet needs
dates
in an unambiguous format, else it wont be able to understand which date
is meant. That means ISO 8601, US format or perhaps other formats, but
not UK format. Here are samples of those.

format$(yourdat e, "yyyy-mm-dd")
format$(yourdat e, "mm\/dd\/yyyy")

See for instance http://allenbrowne.com/ser-36.html for more info.

--
Roy-Vidar
Jul 13 '06 #10

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

Similar topics

19
7289
by: Lauren Quantrell | last post by:
I have a stored procedure using Convert where the exact same Convert string works in the SELECT portion of the procedure but fails in the WHERE portion. The entire SP is listed below. Specifically, I have a problem with this portion in the WHERE clause: DATEADD(Day,tblMyEventTableName.ReminderDays, @DateNow) Between CONVERT(smalldatetime,str(DATEPART(Month, @DateNow)+1) + '/' + str(DATEPART(Day, tblMyEventTableName.TaskDateTime)) + '/'...
4
5402
by: Jorey Bump | last post by:
I can retrieve today's date: mysql> SELECT CURDATE() AS begin; +------------+ | begin | +------------+ | 2005-06-01 | +------------+ 1 row in set (0.00 sec)
3
14519
by: Matt | last post by:
Hello, I have a query that I would like to schedule in DTS. The criteria of this query checks for records in the table that are within the current quarter. Here is what I have. WHERE submit_date BETWEEN '01/01/2005' AND '03/31/2005' I would like to dynamically generate the Quarter End and Quarter Beginning dates within my where clause based on the date that DTWS
4
1924
by: John M | last post by:
Hi, I have spent some time trying to sort out a date problem (see mail an hour or so ago) and am now getting to see what the problem is. If I present today's date as 07/02/2004 in a search it come up as 02/07/04. as a consequence I can't get the right record selected. How do i ensure all references to dates are as in UK? My PC is ... I think correctly set up. This has driven me round the bend!!
9
2324
by: John Sidney-Woollett | last post by:
Hi I'm building a web app where changes to customer orders are logged in the following table, and I worried about the time that it will take to locate records that need further processing/actioning. Here's the table: create table CUSTOMER.WCCustOrderStatusLog ( WCCustOrderID integer, WCOrderStatusID integer, -- date/time at which some process acknowledged the status
8
14978
by: Notgiven | last post by:
Say you have two dates, 2005-01-01 and 2005-01-24. I want to get a list or array or all the date between and including those two dates. I want to include this list in a query so I need it in a format like: '2005-01-01', '2005-01-02',... Any ideas? thanks
24
19915
by: clare at snyder.on.ca | last post by:
I have a SQL query I need to design to select name and email addresses for policies that are due and not renewed in a given time period. The problem is, the database keeps the information for every renewal in the history of the policyholder. The information is in 2 tables, policy and customer, which share the custid data. The polno changes with every renewal Renewals in 2004 would be D, 2005 S, and 2006 L. polexpdates for a given customer...
5
5163
by: DW | last post by:
I have a query in Access 2003 that has the following criteria SELECT tblOrder.SessionDate, tblMenus.Item_Name, tblOrder.Type, Format$(tblorder!SessionDate,"Short Time") AS SessionTime, Sum(tblMenus.Item_Quantity) AS MenuCount INTO tblSessionQuery FROM tblOrder, tblMenus WHERE (((tblOrder.Order_ID)=.) AND ((Format$(!,"mm/dd/yyyy")) Between Format$(!!,"mm/dd/yyyy") And Format$(!!,"mm/dd/yyyy")))
7
2419
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. 1. To search for all records between 2 dates and display them in a report 2. To be able to show all records which have a selection against them made from a combo box 3. To be able to combine the two, selecting the option from a combo and then...
0
9480
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
10315
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
10085
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
9947
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5379
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...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2877
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.