Hi everyone,
Tried using this SQL below - SELECT
-
tblIncident.DateObtained,
-
tblIncident.DateOfExpiry,
-
IIf([DateObtained] Is Null
-
Or [DateOfExpiry] Is Null,
-
"",
-
DateDiff("yyyy",
-
[DateObtained],
-
[DateOfExpiry])-
-
IIf(Format([DateObtained],"mmdd")>
-
Format([DateOfExpiry],
-
"mmdd"),1,0))
-
AS Years,
-
IIf([DateObtained] Is Null
-
Or [DateOfExpiry] Is Null,
-
"",
-
IIf(Day([DateObtained])<=Day([DateOfExpiry]),
-
DateDiff("m",[DateObtained],[DateOfExpiry])
-
-[Years]*12,
-
DateDiff("m",[DateObtained],[DateOfExpiry])-[Years]*12-1))
-
AS Months,
-
IIf([DateObtained] Is Null
-
Or [DateOfExpiry] Is Null,
-
"",
-
DateDiff("d",DateAdd("m",[Months],
-
DateAdd("yyyy",[Years],[DateObtained])),
-
[DateOfExpiry]))
-
AS Days
-
FROM tblIncident;
A record contains
5/8/2005 - Date1
31/8/1956 - Date2
Date2 - Date1
The query returns me this result:
49 Yrs, -1 Mth, 5 Days
The negative value will appear whenever both date contain same month and date1 day is smaller than date2 days.
Any kind soul knows how to improve this sql.
Thanks very much in advance.
2 1446 zmbd 5,501
Expert Mod 4TB
HappyGala;
That's alot of nested IIF, yea.
Here's what you do...
Take two dates you've had issues with... plug them into your SQL and by hand evaluate the IIF and calcs...
Once you do that, the error in the calculations will become very obvious.
HappyGala,
Oddly enough, when I use your SQL, here are the results I get: - DateObtained DateExpiry Results
-
5/8/2005 31/8/1956 -49, 0, 26
-
31/8/1956 5/8/2005 48, 11, 5
-
Which, appears to work....
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Matthew Wilson |
last post by:
Hi-
I just discovered this:
>>> -1 // 12
-1
>>> 1 // 12
0
>>>
|
by: Imbaud Pierre |
last post by:
integer division and modulo gives different results in c and python,
when negative numbers
are involved. take gdb as a widely available c interpreter
print -2 /3
0 for c, -1 for python.
more...
|
by: James Fortune |
last post by:
Several U.S. holidays are defined as the Nth Xday of a given month.
For example, Thanksgiving Day is on the 4th Thursday in November. I
found the following functions useful in calculating the date...
|
by: Ashish Sheth |
last post by:
Hi All,
In C#, How can I get the difference between two dates in number of months?
I tried to use the Substract method of the DateTime class and it is
giving me the difference in TimeSpan,From...
|
by: Ante Perkovic |
last post by:
Hi,
How to declare datetime object and set it to my birthday, first or
last day of this month or any other date.
I can't find any examples in VS.NET help!
BTW, what is the difference...
|
by: felecha |
last post by:
Is there a control that I can put on a Form that would let a user
select just the month value? I tried to find a way to make the
DateTimePicker or the Month Calendar do what I want but I can't. ...
|
by: prosoft |
last post by:
When I use
Dim myDTFI As DateTimeFormatInfo = New CultureInfo("he-IL",
True).DateTimeFormat
Dim strhmon1 As String = (myDTFI.GetMonthName(hmon1))
MsgBox(strhmon1)
I get the local name of the...
|
by: illegal.prime |
last post by:
So I see from the documentation here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemCollectionsArrayListClassBinarySearchTopic.asp
That the code uses the...
|
by: ben.carbery |
last post by:
Hi,
I have just written a simple program to get me started in C that
calculates the number of days since your birthdate.
One thing that confuses me about the program (even though it works) is...
|
by: edfialk |
last post by:
Hi, does anyone happen to know of a script that would return the
number of seconds in a month if I give it a month and a year?
My python is a little weak, but if anyone could offer some...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: 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,...
|
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...
|
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...
| |