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

DateTime problem

Hi folks

I have an C# app. connecting to a MS-ACCESS database with several tables.

In a specific situations I have problems with a DateTime type in a table.
The problem is when I want to select records from a table in a specific
period the day
and month seems to be swapped in the query, but it only happens when the
swapping
yields a valid date eg.

12/10/2005 (12. Oct. 2005) returns records on 10/12/2005 (10. Dec. 2005)

23/05/2005 (23. May 2005) returns records correctly since 05/23/2005 is not
a valid date with danish regional settings.

The query is:
"SELECT [ID], [Activity], [BeginDate] FROM TimeReg WHERE [BeginDate] >= #" +
_start + "# " AND [BeginDate] <= #" + _end + "#"

_start and _end are of type DateTime

My PC in running with danish regional settings and if I shift to en-US
settings in the control panel, this fixes the problem, but that is not a
solution for me.

Any suggestions to solve this problem

Thanks in advance.

Kim W.


Nov 13 '05 #1
4 2752
Kim Würtz wrote:
Hi folks

I have an C# app. connecting to a MS-ACCESS database with several
tables.
In a specific situations I have problems with a DateTime type in a
table. The problem is when I want to select records from a table in a
specific period the day
and month seems to be swapped in the query, but it only happens when
the swapping
yields a valid date eg.

12/10/2005 (12. Oct. 2005) returns records on 10/12/2005 (10. Dec.
2005)
23/05/2005 (23. May 2005) returns records correctly since 05/23/2005
is not a valid date with danish regional settings.

The query is:
"SELECT [ID], [Activity], [BeginDate] FROM TimeReg WHERE [BeginDate]
= #" + _start + "# " AND [BeginDate] <= #" + _end + "#"


_start and _end are of type DateTime

My PC in running with danish regional settings and if I shift to en-US
settings in the control panel, this fixes the problem, but that is
not a solution for me.

Any suggestions to solve this problem

Thanks in advance.

Kim W.


Date literals in Access must use US format (mm/dd/yyyy) or an unambiguous format
like dd-mmm-yyyy.
--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
Nov 13 '05 #2
Kim Würtz wrote in message
<42*********************@dread11.news.tele.dk> :
Hi folks

I have an C# app. connecting to a MS-ACCESS database with several tables.

In a specific situations I have problems with a DateTime type in a table.
The problem is when I want to select records from a table in a specific
period the day
and month seems to be swapped in the query, but it only happens when the
swapping
yields a valid date eg.

12/10/2005 (12. Oct. 2005) returns records on 10/12/2005 (10. Dec. 2005)

23/05/2005 (23. May 2005) returns records correctly since 05/23/2005 is not
a valid date with danish regional settings.

The query is:
"SELECT [ID], [Activity], [BeginDate] FROM TimeReg WHERE [BeginDate] >= #" +
_start + "# " AND [BeginDate] <= #" + _end + "#"

_start and _end are of type DateTime

My PC in running with danish regional settings and if I shift to en-US
settings in the control panel, this fixes the problem, but that is not a
solution for me.

Any suggestions to solve this problem

Thanks in advance.

Kim W.


Hi!

Yes, it's by default, when using dynamic SQL - think of it, we're
passing
a string to the Jet engine, where it doesn't know what we are sending
-> it needs an unambiguous format. In VBA, one would format using
for instance something like this:

.... [BeginDate] <= #" + format(_end,"yyyy-mm-dd") + "#"

but how it's done in C#, I don't know. Just note that another format
suggestion showed "dd/mm/yyyy" will barf on danish settings to, cause
of the date separator, something like this "mm\/dd\/yyyy" can then be
used.
More info can be found here http://allenbrowne.com/ser-36.html

I think you should be able to utilzie the parameters collection
of the object type you're using, even on dynamic SQL. An NG
dedicated to C# would probably be of more assistance with regards
of actual syntax.

--
Roy-Vidar

Nov 13 '05 #3
RoyVidar wrote in message <mn***********************@yahoo.no> :

I said:
Just note that another format suggestion showed "dd/mm/yyyy"
will barf on danish settings to

But meant "mm/dd/yyyy" -> "mm\/dd\/yyyy"

--
Roy-Vidar

Nov 13 '05 #4
Hi

Thanks for the advices, it really saved my day. Using a little
string manipulation and explicity tell the MS-Access the DateTime
format using the FORMAT in the sql string solved the problem.

Best regards

Kim W.

"RoyVidar" <ro*************@yahoo.no> wrote in message
news:mn***********************@yahoo.no...
RoyVidar wrote in message <mn***********************@yahoo.no> :

I said:
Just note that another format suggestion showed "dd/mm/yyyy"
will barf on danish settings to

But meant "mm/dd/yyyy" -> "mm\/dd\/yyyy"

--
Roy-Vidar

Nov 13 '05 #5

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

Similar topics

4
by: Mingus Tsai | last post by:
Hello- please help with unpickling problem: I am using Python version 2.3.4 with IDLE version 1.0.3 on a Windows XPhome system. My problem is with using cPickle to deserialize my pickled...
2
by: Rey | last post by:
Howdy all. My problem deals w/inserting nulls into database (SQL Svr 2K) for the datetime fields activityDate and followUpDate where nulls are allowed. >From the web form, the user can type...
8
by: Alan Silver | last post by:
Hello, I have a custom control that displays the date and time. I currently have properties for the day, month, year, hour and minute, which have to be set separately. This is inefficient. I...
5
by: I am Sam | last post by:
I have created this DateTime object and instanced it I think correctly DateTime myClubNow1=new...
9
by: Phil B | last post by:
I am having a problem with a datetime from a web services provider The provider is sending the following SOAP response <?xml version="1.0" encoding="utf-8"?> <soap:Envelope...
3
by: pranesh.nayak | last post by:
I'm facing an error:"String was not recognized as a valid DateTime" whille accessing DateTime from webservice. And when I try to set DateTime to the same webservice it fails with error:"Date...
6
by: JFieseler | last post by:
Hi all, in a huge project i have the following problem. I create an object which contains many private members (i know that this is not correct, but it is a single use migration program). The...
5
by: iulian.ilea | last post by:
Is correct to have a varchar field and insert dates of type dd/mm/yyyy into it? I choose this method because I have an application that runs on more than one server. So, if I used a datetime field...
4
by: =?Utf-8?B?QmFidU1hbg==?= | last post by:
Hi, I have a GridView and a SqlDataSource controls on a page. The SqlDataSource object uses stored procedures to do the CRUD operations. The DataSource has three columns one of which -...
4
by: =?Utf-8?B?c2lwcHl1Y29ubg==?= | last post by:
Hi I am having a problem formatting a string when the time is in format hh.mm.ss - used in Europe Parse seems ok when the date uses "/" or "." as seperator but I get an exception when time...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.