Solved

date/time comparsion with sql locale setting problem

Posted on 2004-08-01
8
181 Views
Last Modified: 2012-05-05
I am writing an application with vb6 and access 97

I pass query which will compare the database's date/time with the current date/time. eg:

SELECT  (CAExpiry - #" & Now & "#)  AS ToBeExpired, FROM CompanySearch

But my users will use different language and have different locale setting for date/time

So, some users have error with the query

I would like to ask what is the safest way to make sure different setting of locale can use my program?

Thanks
0
Comment
Question by:leekf
  • 4
8 Comments
 
LVL 19

Expert Comment

by:Shauli
ID: 11688067
The best way is to use dateserial:

Dim myDate As Date
myDate = DateSerial(Year(Now), Month(Now), Day(Now))


S
0
 
LVL 19

Expert Comment

by:Shauli
ID: 11688077
Or, if you want to make sure it is US format:

myDate = Format(Now(), "mm/dd/yyyy")

Or European format:

myDate = Format(Now(), "dd/mm/yyyy")

S
0
 
LVL 2

Author Comment

by:leekf
ID: 11690321
My Access file has specified date/time format: dd/mm/yyyy hh:nn:ss

Does it matter?

Do I have to consider the date/time format of the Access file?

Or, as soon as I specify myDate = Format(Now(), "dd/mm/yyyy")

I can use myDate to compare with the date/time of the Access file?
0
 
LVL 19

Accepted Solution

by:
Shauli earned 50 total points
ID: 11690356
Access dates are always in US format. See MSDN:

..."When you specify the criteria argument, date literals must be in U.S. format, even if you're not using the U.S. version of the Microsoft Jet database engine. For example, May 10, 1996, is written 10/5/96 in the United Kingdom and 5/10/96 in the United States. Be sure to enclose your date literals with the number sign (#) as shown in the following examples.

To find records dated May 10, 1996 in a United Kingdom database, you must use the following SQL statement:

SELECT *
FROM Orders
WHERE ShippedDate = #5/10/96#;             ..."

Therefore you must  force a US format on the user's entry.

S




0
 
LVL 19

Expert Comment

by:Shauli
ID: 11690361
ps. which means to replace the user's European entry with the US format as above.

S
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

680 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question