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

SQL query and system DATE problem

Hi to all.
I have a small problem I hope someone can help me with.
I am running a sql query to a csv file. The query searches for the
total of a column between 2 dates.

This is a copy of one of the query's:

Dim SF_SMT As New OleDb.OleDbCommand("Select count(*) from
fault_records.csv where F4 = '" & lblprod.Text & " ' " & " AND F8 AND
F1 between #" & SelectproductForm.datestart & "# and #" & Now.Date &
"#", conn)

F1 contains the date.F4 is the "product" and F8 the fault code that I'm
totaling.
The query works fine(returns the correct value) if my computer regional
DATE setting is m/d/yyyy. If I change it to d/m/yyyy then the query
returns nothing. It runs , but does not return anything.
Why is this and how can I get around it.

If this software is only running on one machine it would not be to much
of a problem , but if I want to run it on various machines that may
have different DATE setting it won't work.

The software is written in vb.net
Any help would be appreciated.
Cheers
Rob

Nov 21 '05 #1
3 6102
Rob,

I would in your situation not trying to make my SQL string in the way as you
do it, especially not with dates.

Internally in Microsoft systems are used USA style dates. Which makes it
difficult for most of us, however when we know, not that big problem because
it is in the newer systems consequent. However it means that you should
avoid as much as possible to convert dates to strings (only for presentation
purposses)

When you use the commandparameters and not try to convert dates to strings,
the problems are mostly gone.

http://msdn.microsoft.com/library/de...eterstopic.asp

Keep in mind that for OleDB the sequence of adding has to be the same as in
the Selectstring.

I hope this helps?

Cor
"seegoon" <se*******@yahoo.com>
Hi to all.
I have a small problem I hope someone can help me with.
I am running a sql query to a csv file. The query searches for the
total of a column between 2 dates.

This is a copy of one of the query's:

Dim SF_SMT As New OleDb.OleDbCommand("Select count(*) from
fault_records.csv where F4 = '" & lblprod.Text & " ' " & " AND F8 AND
F1 between #" & SelectproductForm.datestart & "# and #" & Now.Date &
"#", conn)

F1 contains the date.F4 is the "product" and F8 the fault code that I'm
totaling.
The query works fine(returns the correct value) if my computer regional
DATE setting is m/d/yyyy. If I change it to d/m/yyyy then the query
returns nothing. It runs , but does not return anything.
Why is this and how can I get around it.

If this software is only running on one machine it would not be to much
of a problem , but if I want to run it on various machines that may
have different DATE setting it won't work.

The software is written in vb.net
Any help would be appreciated.
Cheers
Rob

Nov 21 '05 #2

Cor Ligthert wrote:
Rob,

I would in your situation not trying to make my SQL string in the way as you do it, especially not with dates.

Internally in Microsoft systems are used USA style dates. Which makes it difficult for most of us, however when we know, not that big problem because it is in the newer systems consequent. However it means that you should avoid as much as possible to convert dates to strings (only for presentation purposses)

When you use the commandparameters and not try to convert dates to strings, the problems are mostly gone.

http://msdn.microsoft.com/library/de...eterstopic.asp
Keep in mind that for OleDB the sequence of adding has to be the same as in the Selectstring.

I hope this helps?

Cor
"seegoon" <se*******@yahoo.com>
Hi to all.
I have a small problem I hope someone can help me with.
I am running a sql query to a csv file. The query searches for the
total of a column between 2 dates.

This is a copy of one of the query's:

Dim SF_SMT As New OleDb.OleDbCommand("Select count(*) from
fault_records.csv where F4 = '" & lblprod.Text & " ' " & " AND F8 AND F1 between #" & SelectproductForm.datestart & "# and #" & Now.Date & "#", conn)

F1 contains the date.F4 is the "product" and F8 the fault code that I'm totaling.
The query works fine(returns the correct value) if my computer regional DATE setting is m/d/yyyy. If I change it to d/m/yyyy then the query
returns nothing. It runs , but does not return anything.
Why is this and how can I get around it.

If this software is only running on one machine it would not be to much of a problem , but if I want to run it on various machines that may
have different DATE setting it won't work.

The software is written in vb.net
Any help would be appreciated.
Cheers
Rob


Thanks for the help.
I've got it sorted now. Probably not the best method, but it seems to
work.
I reading the system date into a string. Converting it to M,d,yyyy
format with the FORMAT command ,
and then converting back to a date type with CDATE.
Seems to be doing the job fine.
Thanks
Rob

Nov 21 '05 #3

Cor Ligthert wrote:
Rob,

I would in your situation not trying to make my SQL string in the way as you do it, especially not with dates.

Internally in Microsoft systems are used USA style dates. Which makes it difficult for most of us, however when we know, not that big problem because it is in the newer systems consequent. However it means that you should avoid as much as possible to convert dates to strings (only for presentation purposses)

When you use the commandparameters and not try to convert dates to strings, the problems are mostly gone.

http://msdn.microsoft.com/library/de...eterstopic.asp
Keep in mind that for OleDB the sequence of adding has to be the same as in the Selectstring.

I hope this helps?

Cor
"seegoon" <se*******@yahoo.com>
Hi to all.
I have a small problem I hope someone can help me with.
I am running a sql query to a csv file. The query searches for the
total of a column between 2 dates.

This is a copy of one of the query's:

Dim SF_SMT As New OleDb.OleDbCommand("Select count(*) from
fault_records.csv where F4 = '" & lblprod.Text & " ' " & " AND F8 AND F1 between #" & SelectproductForm.datestart & "# and #" & Now.Date & "#", conn)

F1 contains the date.F4 is the "product" and F8 the fault code that I'm totaling.
The query works fine(returns the correct value) if my computer regional DATE setting is m/d/yyyy. If I change it to d/m/yyyy then the query
returns nothing. It runs , but does not return anything.
Why is this and how can I get around it.

If this software is only running on one machine it would not be to much of a problem , but if I want to run it on various machines that may
have different DATE setting it won't work.

The software is written in vb.net
Any help would be appreciated.
Cheers
Rob


Thanks for the help.
I've got it sorted now. Probably not the best method, but it seems to
work.
I reading the system date into a string. Converting it to M,d,yyyy
format with the FORMAT command ,
and then converting back to a date type with CDATE.
Seems to be doing the job fine.
Thanks
Rob

Nov 21 '05 #4

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

Similar topics

8
by: Adam Louis | last post by:
I would like help resolving this problem. I'm a novice who's been hired to query a hospital database and extract useful information, available to me only in a dynamically generated, downloadable...
8
by: Maxi | last post by:
There is a lotto system which picks 21 numbers every day out of 80 numbers. I have a table (name:Lotto) with 22 fields (name:Date,P1,P2....P21) Here is the structure and sample data: ...
6
by: Bill R via AccessMonster.com | last post by:
I have a query: SELECT tblCalendar.CalendarDay AS LastSunday FROM tblCalendar WHERE (((tblCalendar.CalendarDay)>=(Now()-7) And (tblCalendar.CalendarDay)...
3
by: Rob | last post by:
I have a problem I can't seem to solve although it should be easy. I've done these many times before. But I keep getting an exception, "Line 1: Incorrect syntax near 'GetFinancialData'." This...
3
by: Jim in Arizona | last post by:
I have a gridview that's being populated from an access db query. The problem I'm having is that the date/time fields in access that are populating the gridview are showing both date and time, when...
10
by: Daniel | last post by:
In Microsoft Access I can write a query that includes the criteria: Between Date()-7 And Date() to retrieve the records from a table that fall within the last week. I'm trying to write a...
22
by: Stan | last post by:
I am working with Access 2003 on a computer running XP. I am new at using Access. I have a Db with a date field stored as mm/dd/yyyy. I need a Query that will prompt for the month, ie. 6 for...
9
by: Millie18 | last post by:
Hi, I’m trying to set up a query to find all dates on or between a start and end date. Table name and field names I’ve used: Tbl_bookings Booking No Boarding Arrival Date Boarding Departure...
5
by: Just_a_fan | last post by:
I tried to put an "on error" statement in a routine and got the message that I cannot user "on error" and a lamda or query expression in the same routine. Help does not list anything useful for...
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
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
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
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.