Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

date/time comparsion with sql locale setting problem

Posted on 2004-08-01
8
180 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

809 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