Date problem

A

alvin Kuiper

Hi
I work in access english 2007, but on a danish Pc
so my date format is in danish dd-mm-yyyy

I try theis code:
strsql = "SELECT * FROM MaskinUdlejeLinje WHERE ((#" & StartDato.Value & "#
Between [startdato] And [slutdato])) "

Startdato and slutdato is a date field in my table

If StartDato.Value = 13-12-2008 then it works allright
and find my record there have startdato 12-12-2008 and slutdato 18-12-2008

But if i use 03-12-2008 then it can't find my record there have
startdato 02-12-2008 and slutdato 04-12-2008

I belive it something about date format but can't solve this problem

If i run it as a querie in access then it works, but not in my code

Can someone help her ?
 
S

Stefan Hoffmann

hi Alvin,

alvin said:
I work in access english 2007, but on a danish Pc
so my date format is in danish dd-mm-yyyy
This is an Access specific problem, date literals must always be in the
American format.
I try theis code:
strsql = "SELECT * FROM MaskinUdlejeLinje WHERE ((#" & StartDato.Value & "#
Between [startdato] And [slutdato])) "
I'm using this function (place it in a standard module):

Public Function SQLDateTime(ADateTime As Date) As String

SQLDateTime = Format(ADateTime, "\#m\/d\/yyyy hh\:nn\:ss\#")

End Function

strsql = "SELECT * " & _
"FROM MaskinUdlejeLinje " & _
"WHERE " & SQLDateTime(StartDato.Value) & " " & _
"BETWEEN [startdato] AND [slutdato]"


mfG
--> stefan <--
 
J

John Spencer

For an explanation, see Allen Browne's rather comprehensive explanation.

International Dates in Access at:
http://allenbrowne.com/ser-36.html

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top