Hi there,
I have created Job table where I have to enter the startdate and finish date for each job I work on. The problem is that some jobs only last 1 day. I have a field called JobLength where I am trying to calculate the numerical difference between the startdate and the enddate, but it always comes back with 0. If I work on a job starting on 17/11/06 and finishing on 17/11/06, how do I get it to say 1 (as in 1 day?).
I have tried DateDiff, when using the form: - =DateDiff("d",[JobStartDate],[JobFinishDate])
But it still comes up with one. Any ideas?
I am using MS Access 2003.
9 3051
Hi there,
I have created Job table where I have to enter the startdate and finish date for each job I work on. The problem is that some jobs only last 1 day. I have a field called JobLength where I am trying to calculate the numerical difference between the startdate and the enddate, but it always comes back with 0. If I work on a job starting on 17/11/06 and finishing on 17/11/06, how do I get it to say 1 (as in 1 day?).
I have tried DateDiff, when using the form: - =DateDiff("d",[JobStartDate],[JobFinishDate])
But it still comes up with one. Any ideas?
I am using MS Access 2003.
Two possibilities come to mind. - Use IIF() to return one if they match, otherwise DateDiff.
- =DateDiff("d",[JobStartDate],[JobFinishDate])-([JobStartDate]=[JobFinishDate])
Note, True generally returns -1 which is why we subtract rather than add.
I suppose the problem with either of these approaches is, are the values the same or not? If this is a date only, they would be. If it includes time, they wouldn't.
I suppose the problem with either of these approaches is, are the values the same or not? If this is a date only, they would be. If it includes time, they wouldn't.
On further reflection, it might be messy but you could probably overcome this problem (if it exists) by checking whether the returned value from DateDiff was zero, rather than whether the dates are the same. In other words - =DateDiff("d",[JobStartDate],[JobFinishDate])
-
- (DateDiff("d",[JobStartDate],[JobFinishDate]) = 0)
Another possibility would be to add, say, 0.9 to the result then use the Int function to chop off the decimal places. - =Int(DateDiff("d",[JobStartDate],[JobFinishDate]) + 0.9)
I don't know whether any of these are any good, but they might give you some ideas to play with.
Ok, scratch the Int idea - it won't work. I was thinking of DateDiff returning a decimal part of a day, or something.
Sorry about this folks, just brainstorming with myself, I guess.
Oh! And bumping up my message count, naturally. After all, that's what we're here for. :)
MMcCarthy 14,534
Recognized Expert Moderator MVP
I think your problem is more basic than that. If you start a job on 17/11/06 and finish on 18/11/06, I assume you want to return 2 days but this will only return 1. - =DateDiff("d", #17/11/2006#, #18/11/2006#)
This should solve your problem: - =DateDiff("d",[JobStartDate]-1,[JobFinishDate])
I think your problem is more basic than that. If you start a job on 17/11/06 and finish on 18/11/06, I assume you want to return 2 days but this will only return 1.
Good point! You could just add 1 to the result, in that case. - =DateDiff("d",[JobStartDate],[JobFinishDate])+1
Not much difference either way I suppose, Mary.
I think your problem is more basic than that. If you start a job on 17/11/06 and finish on 18/11/06, I assume you want to return 2 days but this will only return 1. - =DateDiff("d", #17/11/2006#, #18/11/2006#)
This should solve your problem: - =DateDiff("d",[JobStartDate]-1,[JobFinishDate])
Complete and utter genius!!!
Thank you all for your help - problem solved. I added -1 to JobStartDate and with the dates (jobstartdate) 17/11/2006 and (jobfinishdate) 17/11/06 the joblength came back as 1 not 0.
So thanks again. It is much appreciated :)
MMcCarthy 14,534
Recognized Expert Moderator MVP
Good point! You could just add 1 to the result, in that case. - =DateDiff("d",[JobStartDate],[JobFinishDate])+1
Not much difference either way I suppose, Mary.
Either way it works, the problem is DateDiff() doesn't include the first date in it's count.
Mary
Either way it works, the problem is DateDiff() doesn't include the first date in it's count.
Mary
Which is only as it should be, of course. I mean, you could hardly claim that the difference between a date and the same date is a day.
MMcCarthy 14,534
Recognized Expert Moderator MVP
Which is only as it should be, of course. I mean, you could hardly claim that the difference between a date and the same date is a day.
True!
Mary
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Tiernan |
last post by:
Hi all
I'm looking for a way to find the number of weekdays between 2 dates
In my form I have three fields for a begin date (dd)(mm)(yyyy) and
three for the end date (dd)(mm)(yyyy)
Now these...
|
by: Bambero |
last post by:
Hello all
Problem like in subject. There is no problem when I want to count days
between two dates. Problem is when I want to count years becouse of
leap years.
For ex.
between
2002-11-19...
|
by: edwardfredriks |
last post by:
I'm looking for a script that, instead of counting down, can "count up"
from a given date. So the output should be something like "(xx) days
since (date/event)" or "(date/event) was (xx) days ago"....
|
by: David Mitchell |
last post by:
I have tried using the following code to count the specific number of
each weekday but get a compile error "User defined type not defined"
which I think relates to the first line of the function: -...
|
by: james |
last post by:
I have a problem that at first glance seems not that hard to figure out. But, so far, the answer has escaped me. I have an old
database file that has the date(s) stored in it as number of days.
An...
|
by: jpr |
last post by:
Friends, I have a form with four fields, date1, date2, date3 and date4.
All these have all a mm/dd/yyyy format and have their source to a
table.
I need to add an unbound control (I will name...
|
by: Jannick |
last post by:
Help..please!
I'm a rookie in terms of VB, but I'm desperately trying to make Access
count the number of days between two dates and then subtract the
weekends. Can anyone tell me what is wrong...
|
by: Tim Chase |
last post by:
I've been trying to come up with a good algorithm for determining
the starting and ending dates given the week number (as defined
by the strftime("%W") function).
My preference would be for a...
|
by: vspsdca |
last post by:
Hi,
I'm quite new to the world of VBA so any help you could extend will help me a lot with my project.
I have a database of Change Requests from our users. I have two date boxes, one is Date...
|
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: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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...
|
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...
|
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...
|
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,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |