473,425 Members | 1,872 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,425 software developers and data experts.

Ms Access Time Calculations.

Hello,

I am a new member and am glad to a part of this forum.

I am facing a slight problem while doing time calculations in MS access. I ve prepared a time sheet for my workers. Their regular time is till 17:00 hrs and anything above that is overtime. I am using the formula DateDiff("n",[Regular Time],[Time Out])/60. I am able to calculate the overtime if the worker finishes his work before the day ends. However , if he works untill for eg 2:00 AM , (i.e 9 hrs of over time) , i get a negative result.

Can this be worked out .

Thanks much in advance
Aug 24 '07 #1
16 3108
NeoPa
32,556 Expert Mod 16PB
You have (accidentally) posted this question in the Access Articles section. This is NOT an article.
I'm moving this to the main Access questions forum.

MODERATOR.
Aug 24 '07 #2
NeoPa
32,556 Expert Mod 16PB
Hello,

I am a new member and am glad to a part of this forum.

I am facing a slight problem while doing time calculations in MS access. I ve prepared a time sheet for my workers. Their regular time is till 17:00 hrs and anything above that is overtime. I am using the formula DateDiff("n",[Regular Time],[Time Out])/60. I am able to calculate the overtime if the worker finishes his work before the day ends. However , if he works untill for eg 2:00 AM , (i.e 9 hrs of over time) , i get a negative result.

Can this be worked out .

Thanks much in advance
Use the Mod operator. This will require ensuring that the value is an integer when processed but shouldn't be too much of a problem.
What are the units you're working in (IE. What does a value of 1 mean)?
Aug 24 '07 #3
Scott Price
1,384 Expert 1GB
Try changing your Time fields to Date&Time fields, such as by using the Now() function for logging the time in and time out.

Date/Time functions can be tricky because of the way Access stores and calculates time, but this should actually be a simple way to calculate the difference you are looking for.

Regards,
Scott
Aug 24 '07 #4
You have (accidentally) posted this question in the Access Articles section. This is NOT an article.
I'm moving this to the main Access questions forum.

MODERATOR.
Sorry , i am new to this . I'll keep this in mind henceforth.

Thanks
Aug 24 '07 #5
Scott Price
1,384 Expert 1GB
Sorry, Adrian! Must have been posting at the same time again...

Regards,
Scott
Aug 24 '07 #6
Try changing your Time fields to Date&Time fields, such as by using the Now() function for logging the time in and time out.

Date/Time functions can be tricky because of the way Access stores and calculates time, but this should actually be a simple way to calculate the difference you are looking for.

Regards,
Scott
For the time in and time out , the data type is set as Date/Time , however the result that i get is an integer , so that it calculates the exact overtime hrs.

U mentioned about the Now() function; is that VB . I ve no prior knowledge of VB. All i am using is tables and queries to do the above.
Aug 24 '07 #7
NeoPa
32,556 Expert Mod 16PB
Sorry, Adrian! Must have been posting at the same time again...

Regards,
Scott
Don't be daft Scott! You have every right to post your ideas in here whether I choose to or not :)

That reminds me I need to get your "Expert" invite off to you as soon as. I'll get it out today if humanly possible :)
Aug 24 '07 #8
NeoPa
32,556 Expert Mod 16PB
shreyansghia,
Have you looked at post #3?
If so, can you provide answers please.
An alternative approach is to say :
Expand|Select|Wrap|Line Numbers
  1. If datStart > datEnd then datEnd = datEnd + 1
where Date/Time fields store days as 1.
You then continue as before.

Of course, this can only be a problem if you don't store the Date/Time values fully in the first place :/
Aug 24 '07 #9
Scott Price
1,384 Expert 1GB
Thanks again, Adrian!

If you put this:
Expand|Select|Wrap|Line Numbers
  1. =Date() & " " & #17:00#
in the default value of your Regular Time field at the table level, it will automatically enter the current Date (8/24/2007, according to my computer) and the normal quitting time of 17:00 hours.

Depending on how you enter your Time Out data (i.e. manually through a text box, or by clicking a command button, etc.) you can add in the appropriate place
Expand|Select|Wrap|Line Numbers
  1. =Now()
You shouldn't have to change much more than that, as your fields are already being compared, and the calculation as you have it of the date/time should work out fine.

Have to run, and won't be back until this aft... Post more questions as needed, and someone will help :-)

Regards,
Scott
Aug 24 '07 #10
Thanks again, Adrian!

If you put this:
Expand|Select|Wrap|Line Numbers
  1. =Date() & " " & #17:00#
in the default value of your Regular Time field at the table level, it will automatically enter the current Date (8/24/2007, according to my computer) and the normal quitting time of 17:00 hours.

Depending on how you enter your Time Out data (i.e. manually through a text box, or by clicking a command button, etc.) you can add in the appropriate place
Expand|Select|Wrap|Line Numbers
  1. =Now()
You shouldn't have to change much more than that, as your fields are already being compared, and the calculation as you have it of the date/time should work out fine.

Have to run, and won't be back until this aft... Post more questions as needed, and someone will help :-)

Regards,
Scott
Thanks for all the help . I know this might sound strange , but is it ok if i could mail my database to u (Scott) or NeoPa. I ve not been able to fix this thing.
If yes, i need ur email address.

Also just FYI , i am working on Access 2007. Also the records that i would be feeding in is not on daily basis , but rather, at the month end.

Thanks :-)
Aug 24 '07 #11
Scott Price
1,384 Expert 1GB
Thanks for all the help . I know this might sound strange , but is it ok if i could mail my database to u (Scott) or NeoPa. I ve not been able to fix this thing.
If yes, i need ur email address.

Also just FYI , i am working on Access 2007. Also the records that i would be feeding in is not on daily basis , but rather, at the month end.

Thanks :-)

Access 2007? What's that? :-)

Sorry, I'm on Access 2003, and I think NeoPa is also.

If you post more specifically what is not working, we can try to work you through what's wrong... Emailing the db to me isn't an option at this point, since I don't even have Access 2007.

Regards,
Scott
Aug 24 '07 #12
Scott Price
1,384 Expert 1GB
This link is to Allen Browne's website tips and links to A2007 articles. It will help you to read and understand some of the differences between the different versions.

http://allenbrowne.com/Access2007.html

Regards,
Scott
Aug 24 '07 #13
This link is to Allen Browne's website tips and links to A2007 articles. It will help you to read and understand some of the differences between the different versions.

http://allenbrowne.com/Access2007.html

Regards,
Scott

Allright Scott,

Let me make one last attempt. I have 2 tables.

My 1st table has 2 fields: Worker Name and Worker Id.

In my 2nd table , i ve worker ID , work date, time in , time out, regular time Then i created a simple query having the fields mentioned in the 2nd table and plus the Overtime field which calculates the extra hrs worked.

In the design view of the query , in the field row i ve

Expand|Select|Wrap|Line Numbers
  1.  overtime:DateDiff("n",[Regular Time],[Time Out])/60  
I ve liked the 1st table with the query ( the link being worker id.)

Lastly, the codes that u ve mentioned above , where do i write them. In the field row of the design view? Or is it VB , i dont know VB at all . :-)

Thanks a lot.
Aug 25 '07 #14
Scott Price
1,384 Expert 1GB
Good morning!

The first one code that I mentioned will go in the default value row of your table design view for the field Regular Time.

Right click on your table, choose Design View. Left click once on the name of your field, at the bottom of the design view grid window you will see the properties for that field. Paste this:
Expand|Select|Wrap|Line Numbers
  1. =Date() & " " & #17:00#
in the Default Value.

The next question is, how do you enter your Time Out data? Do you manually type in what time the person leaves work? Do you have a combo box to choose a time selection? Do you have a command button that when you click, it enters a specified time?

Since you are doing this once a month, I suspect that you are typing these in manually. If that is the case, then you will only need to do one thing more: type in the date as well as the time: i.e. 8/25/2007 19:00

Any other questions, I'll be glad to try to explain a little more.

There shouldn't be any need to change the design of your query, as the DateDiff() function works with any flavor of date/time that you throw at it.

Regards,
Scott
Aug 25 '07 #15
Good morning!

The first one code that I mentioned will go in the default value row of your table design view for the field Regular Time.

Right click on your table, choose Design View. Left click once on the name of your field, at the bottom of the design view grid window you will see the properties for that field. Paste this:
Expand|Select|Wrap|Line Numbers
  1. =Date() & " " & #17:00#
in the Default Value.

The next question is, how do you enter your Time Out data? Do you manually type in what time the person leaves work? Do you have a combo box to choose a time selection? Do you have a command button that when you click, it enters a specified time?

Since you are doing this once a month, I suspect that you are typing these in manually. If that is the case, then you will only need to do one thing more: type in the date as well as the time: i.e. 8/25/2007 19:00

Any other questions, I'll be glad to try to explain a little more.

There shouldn't be any need to change the design of your query, as the DateDiff() function works with any flavor of date/time that you throw at it.

Regards,
Scott

Hello Scott ,

Thanks a lot . It does work with your above guidance. However i had to make a few changes in my table and query. If you remember , i told you at the data is put once , at the end of the month. So if use the code

Expand|Select|Wrap|Line Numbers
  1. =Date() & " " & #17:00#
in the Default Value, then for all the values it would be the date when the data is feeded in. So to overcome this , i ve made another column in my table which would record the date when the worker exists the factory (This is required when the worker works even past midnight).

Thus my query has Work Date , Time In , Time Out ,Out Date,
Regular Time ( here i would have
Expand|Select|Wrap|Line Numbers
  1. [Work date] & " " & #17:00#
Another column which would be
Expand|Select|Wrap|Line Numbers
  1. [Out date] & " " & [Time Out]
.

And finaly i could use DateDiff to get the overtime hrs .

Thanks a lot . It was a great help :-)
Aug 27 '07 #16
Scott Price
1,384 Expert 1GB
Glad to be able to help, and thanks for posting back with what worked for you!

Regards,
Scott
Aug 27 '07 #17

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

Similar topics

63
by: Jerome | last post by:
Hi, I'm a bit confused ... when would I rather write an database application using MS Access and Visual Basic and when (and why) would I rather write it using Visual Studio .Net? Is it as easy...
11
by: lduperval | last post by:
Hi, I`m trying to do date calculations in three types of time zones: local, GMT and specified. The issue I am facing is that I need to be able to specify a date in the proper time zone, and I`m...
1
by: bluerocket | last post by:
I have searched this group, and am not finding the answer I am looking for -- hope you can help. I have a front-end MS Access database hooked via a MyODBC link to a MySQL database. A modified...
9
by: MacDermott | last post by:
I have an Access MDB which instantiates a class in a custom DLL, manipulates it for a while, then sets it equal nothing. The MDB does other things,too, and generally behaves itself as desired....
49
by: Yannick Turgeon | last post by:
Hello, We are in the process of examining our current main application. We have to do some major changes and, in the process, are questionning/validating the use of MS Access as front-end. The...
6
by: migueltxa | last post by:
Hi all, I have a problem with some calculations in MS Access 2003. I have 3 fields (Qty, Price and VolumeUSD) in a form and the following formula: VolumeUSD = Qty * Price. Qty and VolumeUSD...
4
by: MrsBean | last post by:
I've been working on learning how to use PHP with MS Access, and as long as I use ODBC, I can make it work. I want to use a DSNless connection. Everthing I have tried has failed. Can anyone show...
2
by: Michael Bialowas | last post by:
Hello all, I have been searching the net endlessly and found this ng, so I thought I would give a try. Anyways, I have a few problems I am trying to implement a combo box which presently contains...
4
by: Wiline | last post by:
Hi, I'm new at using Microsoft Access (2000), and I've been working on a relatively simple scientific database. I've created a "MakeTable" query, which has worked well in the past and I update...
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

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.