Solved

date/time comparsion with sql locale setting problem

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now