Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FUNCTION TO CONVERT FIELDS TO MONTHS !!

Status
Not open for further replies.

sereleg

Programmer
Mar 13, 2005
26
0
0
US
I will appreciate any help to calculate the fields below into month:
Example:
For productID =1019 How many month are
from 20/4/2005 to 26/05/2005 the result in this case could be 1 and 6 days approximadamente or 1.2 moth

PID FDAY FMONTH FYEAR TDAY TMONTH TYEAR
1019 20 4 2005 26 5 2005
1020 10 11 2004 26 2 2005


Thanks for any help !!

 
Probably the best shot is:
Code:
select (TYEAR*12 + TMONTH) - (FYEAR*12 + FMONTH) - case when TDAY >= FDAY then 0 else 1 end as MONTHDIFF,
TDAY - FDAY as DAYDIFF
from myTable
order by PID
Note that months have different number of days, so these information have only visual/presentation purpose.

------
heisenbug: A bug that disappears or alters its behavior when one attempts to probe or isolate it
schroedinbug: A bug that doesn't appear until someone reads source code and realizes it never should have worked, at which point the program promptly stops working for everybody until fixed.

[ba
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top