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

Set a limit to dateDiff

22
I created a query with calculated field months:
Expand|Select|Wrap|Line Numbers
  1. DateDiff("m", 
  2.     [dateacquired], 
  3.     [Forms]![form2]![txtendingdate])+1
I also have a field lifeTime, what i want to do is to set a limit to months fields so that it will not be greater than lifeTime
Jun 21 '18 #1

✓ answered by Nauticalgent

Try using this as the fields control source:

Expand|Select|Wrap|Line Numbers
  1. =IIf(
  2.     DateDiff("m", 
  3.         [dateacquired], 
  4.         [Forms]![form2]![txtendingdate]) + 1 <= [lifetime], 
  5.     DateDiff("m", 
  6.         [dateacquired], 
  7.         [Forms]![form2]![txtendingdate]) + 1, 
  8.     [lifetime])
Sloppy as hell, but it should work...

6 1180
Nauticalgent
100 64KB
Try using this as the fields control source:

Expand|Select|Wrap|Line Numbers
  1. =IIf(
  2.     DateDiff("m", 
  3.         [dateacquired], 
  4.         [Forms]![form2]![txtendingdate]) + 1 <= [lifetime], 
  5.     DateDiff("m", 
  6.         [dateacquired], 
  7.         [Forms]![form2]![txtendingdate]) + 1, 
  8.     [lifetime])
Sloppy as hell, but it should work...
Jun 21 '18 #2
Mafi
22
Wow! It works perfectly thanks. What can i do to return negetive months to zero. Eg when i view previews years that is b4 dateacquired it gave me negetive months
Jun 21 '18 #3
Nauticalgent
100 64KB
Glad it worked. To set negative numbers to zero, you could nest the IIF statement. I have shown you a quick example, why not give it a try and if you cannot make it work, post back here with what you have tried so we can show you where you may be getting it wrong.

Not that I mind helping out, but I like to be taught to fish rather than having my fish given to me.

Deal?
Jun 21 '18 #4
Nauticalgent
100 64KB
This may give you some ideas:

http://www.simply-access.com/Nested_IIF_Statement.html
Jun 21 '18 #5
Mafi
22
I have gotten it. Thanks alot
Jun 21 '18 #6
Nauticalgent
100 64KB
Good deal. Care to share your solution so that others may learn from your blood, sweat and tears?
Jun 21 '18 #7

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

Similar topics

4
by: CJM | last post by:
I have an ASP page that lists files and folders in a directory. I'm using a cookie to record the last time this page was visited, and I intend to show links that are created/modified from that date...
8
by: inamori | last post by:
I face that problems 07/01/2003 06/30/2006 ---------> it should be 3 01/01/2003 02/28/2005 --------->could i get 2 years and 2 months 01/01/2003 03/01/2005 ...
6
by: Lofty | last post by:
Hi all. I have to write an app that interacts with mySQL (I really must have done some evil, evil stuff in a previous life to be landed with this!) I need to work out the difference in days...
1
by: intl04 | last post by:
I'm trying to set up a query that will include a new field ('Days until completion') whose value is derived from the DateDiff function. I think I have the syntax correct but am not sure. Days...
4
by: Paolo | last post by:
I am having some problem with a Year Function. I have form on which I have 4 field which indicate dates and an additional form which sums those dates: These are the fields: YEARS...
1
by: PMBragg | last post by:
ORINGINAL Post >Thank you in advance. I'm trying to pull all inventory items from December >of the previous year back to 4 years for my accountant. I know this can be >done, but I'm drawing a...
7
by: Adrian | last post by:
I hit on this problem converting a VB.NET insurance application to C#. Age next birthday calculated from date of birth is often needed in insurance premium calculations. Originally done using...
5
by: sr | last post by:
Anyone know of a better way to simulate a datediff for C#, i.e., without referencing the VB.NET runtime? Only added the functionality that was needed for me so it is not the full implementation...
6
by: kevinjwilson | last post by:
I am trying to get the date difference between two dates but I don't want the function to include weekends in the calculation. Does anyone have an idea on how to make this work?
2
by: muddasirmunir | last post by:
i am using vb 6 , i had place two datepicker in form now i want to calcuate differcen of month in two date for this i used the function datediff i had try it withh many syntax but getting error...
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: 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: 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:
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...
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.