Solved

date/time comparsion with sql locale setting problem

Posted on 2004-08-01
8
179 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

803 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