Print Page | Close Window

YTD through end of last month

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Technical Questions
Forum Discription: Formulas, charting data, Crystal syntax, etc.
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=17265
Printed Date: 12 May 2024 at 9:16am


Topic: YTD through end of last month
Posted By: JRSmith
Subject: YTD through end of last month
Date Posted: 10 Aug 2012 at 10:27am
I need to select records based on a date range that starts with January 1 of this year and runs through the last day of last month (based on the current date).
 
I also need to select the same date period for the previous year.
 
Thanks in advance for your help.



Replies:
Posted By: z9962
Date Posted: 13 Aug 2012 at 3:02am

//last day of month
//Date(DateAdd("d",-day(today),DateAdd("m",1,today)))

//First day of year
//date(year(today),1,1)

//last day of month last year
//Date(DATEADD("yyyy",-1,DateAdd("d",-day(today),DateAdd("m",1,today))))

//First day of previous year
//date(year(today)-1,1,1)

therefore
(
[datefield] in date(year(today),1,1) to Date(DateAdd("d",-day(today),DateAdd("m",1,today)))
or
[datefield] in date(year(today)-1,1,1) to Date(DATEADD("yyyy",-1,DateAdd("d",-day(today),DateAdd("m",1,today))))
)


Posted By: JRSmith
Date Posted: 13 Aug 2012 at 10:24am
Thanks for your help.  A little tweeking in my report and it worked.



Print Page | Close Window