Solved

date/time comparsion with sql locale setting problem

Posted on 2004-08-01
8
182 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
[X]
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
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

738 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