Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2020 : Report Design
Message Icon Topic: Calculating months [RESOLVED] Post Reply Post New Topic
Author Message
cajsoft
Newbie
Newbie


Joined: 23 Feb 2009
Location: United Kingdom
Online Status: Offline
Posts: 23
Quote cajsoft Replybullet Topic: Calculating months [RESOLVED]
    Posted: 05 May 2009 at 12:57am

Hi,

I require a formula in CRX to work out the no of complete months between to dates.
 
I dont want to use the datediff function as it doesnt evaulate the dates properly.
 
ie,  stardate is 25/9/2008  enddate is 05/05/2009
 
datediff returns  20  which is incorrect.. it should be 19 complete months
 
hope someone can help
 
Craig.


Edited by cajsoft - 05 May 2009 at 2:37am
IP IP Logged
cajsoft
Newbie
Newbie


Joined: 23 Feb 2009
Location: United Kingdom
Online Status: Offline
Posts: 23
Quote cajsoft Replybullet Posted: 05 May 2009 at 2:37am
I found the answer myself:
WhilePrintingRecords;
//Years
//0.25 accounts for leap year
numbervar Y := (currentdate- {BIRTHDATE})/365.25;
//Months
//30.4375 = 365.25/12 average number of days in a month
numbervar M := Remainder((currentdate- {BIRTHDATE}),365.25)/30.4375;
// check for Months = 12
if truncate(M) = 12
then months := truncate(Y)+1
else months := (truncate(Y) * 12 + truncate(M) );
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.016 seconds.