473,377 Members | 1,153 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,377 software developers and data experts.

Access Date Format Input

2
Hi, I've searched the forum for an answer to my problem. I found an archived thread with the same problem but unfortunatly it's solution isn't very clear. The archived thread is here :

http://www.thescripts.com/forum/thread204990.html

I have a query with the fields [DateWorked] containing short dates, [StaffPIN] containing long ints, and a calculated field:

Hours: WorkedHours([DateWorked], [StaffPIN])

The function WorkedHours() is a user defined function. It returns the number of hours a staff member worked on a day, or an abbreviation of why they didn't work. It works fine in the intermediate window of the VB editor when I type:

?WorkedHours(#01/11/07#,12177)

And it works if I type (the point of giving two examples will be explained later):

?WorkedHours(#21/11/07#,12177)

The formats of the above dates is dd/mm/yy, the same as my (UK) system setting (I have checked).

In the query, however, it only works on dates where the day value is larger than twelve. When the day is less than twelve, the query seems to pass the date to WorkedHours() in the format yy/dd/mm. WorkedHours is expecting it in the dd/mm/yy format.

Hope that made sense!
How can I solve this?
Nov 29 '07 #1
3 4360
MikeTheBike
639 Expert 512MB
Hi, I've searched the forum for an answer to my problem. I found an archived thread with the same problem but unfortunatly it's solution isn't very clear. The archived thread is here :

http://www.thescripts.com/forum/thread204990.html

I have a query with the fields [DateWorked] containing short dates, [StaffPIN] containing long ints, and a calculated field:

Hours: WorkedHours([DateWorked], [StaffPIN])

The function WorkedHours() is a user defined function. It returns the number of hours a staff member worked on a day, or an abbreviation of why they didn't work. It works fine in the intermediate window of the VB editor when I type:

?WorkedHours(#01/11/07#,12177)

And it works if I type (the point of giving two examples will be explained later):

?WorkedHours(#21/11/07#,12177)

The formats of the above dates is dd/mm/yy, the same as my (UK) system setting (I have checked).

In the query, however, it only works on dates where the day value is larger than twelve. When the day is less than twelve, the query seems to pass the date to WorkedHours() in the format yy/dd/mm. WorkedHours is expecting it in the dd/mm/yy format.

Hope that made sense!
How can I solve this?
Hi

In the user defined function you will need to format the date as American date, ie.
Format(YourDateVariable,"mm/dd/yy")

Without seeing the code it is difficult to be more explicit.

VBA (and VB) only recognises/uses American dates, whereas the query designer will look at the local computer settings and adjusts accordingly.
Try typing a date in the criteria field for a date in query design grid, and then look at the SQL view !!

BTW, if you are returning many records, I find queries run faster if you can do the calculation in the query rather that a user defined function. This is normaly possible if the DB is stucture properly!!??


MTB
Nov 29 '07 #2
FishVal
2,653 Expert 2GB
Hi, everyone.

The problem is even worse.
VBA don't accepts dates in mdy format only, but also silently adjusts date which value doesn't fit mdy format.

Example (in VBA immediate window):

? Format(#27/11/2007#, "mmm-dd-yyyy")
Nov-27-2007

? Format(#7/11/2007#, "mmm-dd-yyyy")
Jul-11-2007

and to make you feel proud of it - the best
? Format(#27/11/7#, "mmm-dd-yyyy")
Nov-07-2027

Query builder adjusts dates in the same way.

P.S. Tested on Access 2003, Win XP2, Regional setting - american date format
Nov 29 '07 #3
JEA123
2
Hi

In the user defined function you will need to format the date as American date, ie.
Format(YourDateVariable,"mm/dd/yy")

Without seeing the code it is difficult to be more explicit.

VBA (and VB) only recognises/uses American dates, whereas the query designer will look at the local computer settings and adjusts accordingly.
Try typing a date in the criteria field for a date in query design grid, and then look at the SQL view !!
Works perfectly! Thanks! You don't know how much of a headache I've had with this. Your explanation (and FishVal's) solves other problem I've been having working with dates as well. Thank you both very much.

BTW, if you are returning many records, I find queries run faster if you can do the calculation in the query rather that a user defined function. This is normaly possible if the DB is stucture properly!!??
My database is not huge (user only enters a dozen or so values a day) so performance isn't high on my priorities. I use this function quite alot through out the db so it's more convenient to have a function. Thanks for the advice though, to me it's been invaluable.
Nov 29 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Gerrit Holl | last post by:
Posted with permission from the author. I have some comments on this PEP, see the (coming) followup to this message. PEP: 321 Title: Date/Time Parsing and Formatting Version: $Revision: 1.3 $...
3
by: Jay | last post by:
I previously posted this question under Visual Basic newsgroup, but was advised to re-post here. I'm hoping someone can help me solve an issue I'm having with VB.Net and Access 2000. Here's...
4
by: Richard Hollenbeck | last post by:
I'm trying to write some code that will convert any of the most popular standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan 1908) and compare the first with the second and...
14
by: Sean C. | last post by:
Helpful folks, Most of my previous experience with DB2 was on s390 mainframe systems and the optimizer on this platform always seemed very predictable and consistent. Since moving to a WinNT/UDB...
13
by: Peter James | last post by:
Access 97 If I select New on the Query tab of the db window, and go staight to sql view and type in the following for example: INSERT INTO tblMyTable ( dtDate, txtAny) VALUES (#2003-09-03#,...
9
by: Edward S | last post by:
I budget for a Project in an Excel sheet as illustrated below. The months below are usually a 2 year period i.e. 24 months, though it could be over 24 months depending upon a Project. I then...
4
by: rzhang | last post by:
Hi, We have an Access Application which works fine for most of the users. But there is one user who has the date input problem. When he enter a date field from a form, i.e. 09/03/2004 (Sept....
1
by: abcabcabc | last post by:
I write an application which can let user define own date format to input, How to convert the date string to date value with end-user defined date format? Example, User Defined Date Format as...
6
by: NH | last post by:
I want to allow users to enter dates in a text box in either the US "MM dd yy" format or the UK "dd MM yy" format. But how can I validate these dates? All the date functions e.g. ISdate,...
1
by: saddist | last post by:
Hello, I've been working on access 2000 for few days. I made some forms with textfields where you can type date. Those textfields had input mask set for short date 99/99/0000. Now software have...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.