Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Formula to calculate Prev YTD Days Post Reply Post New Topic
Author Message
katich
Newbie
Newbie


Joined: 25 Jun 2010
Location: United States
Online Status: Offline
Posts: 9
Quote katich Replybullet Topic: Formula to calculate Prev YTD Days
     Posted: 31 Jul 2012 at 6:55am
I need a formula that will return the previous YTD days.  Meaning, if my report is as of 6/30/2012, I want to return the number of days as of 6/30/2011. 
I tried doing the following but it doesn't seem to take into affect leap year.  Any suggestions?
 
 
datepart('y',dateserial(year({@Date}-365),month({@Date})+1,1-1))
 
 
Thanks,

Frank
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 31 Jul 2012 at 7:25am
not sure i understand your request as compared to your formula.
do you want the number of days in last year through the end of the month of a paramaterized date?
IP IP Logged
katich
Newbie
Newbie


Joined: 25 Jun 2010
Location: United States
Online Status: Offline
Posts: 9
Quote katich Replybullet Posted: 01 Aug 2012 at 1:54am

I think my formula i'm showing is not error proof.  I guess i felt there might be a better way to write this formula.  To answer your question, yes. 

IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 01 Aug 2012 at 3:52am
Sorry was not implying anything about the formula, just needed clarity on the expected behavior to try and help.
I unfortuantely found out this year that dateserial() and dateadd() did not act the same with leap year and some of my daily reports ending up coming out with unintended data at that time.
I believe this will work for what you need
datepart('y',dateserial(year(@date)-1,month(@date)+1,1-1))
 
IP IP Logged
katich
Newbie
Newbie


Joined: 25 Jun 2010
Location: United States
Online Status: Offline
Posts: 9
Quote katich Replybullet Posted: 02 Aug 2012 at 8:59am
Oh, no need to apologize.  Thank you, this appears to work well, I truly appreciate it. 
IP IP Logged
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