The Result Data Newsletter   
Volume 802 - February 2008   
© Copyright 2008 Result Data Consulting, Ltd.  614-505-0770  www.resultdata.com   

    Result Data Home Page  |  Newsletter Archive  |  Upcoming Events  |  Classes & Workshops  |  Request Information
Upcoming Events:  BusinessObjects Calming the Storm Seminar: 3/4,  SharePoint/eCopy Seminar: 3/6,  Microsoft SQL Server User Group: 3/28

Return to Newsletter Contents...

 

Turning Back Time

by: Aaron Zecman, Consultant, CRCP, MSCE

I have had plenty of students ask how they can turn back time and it’s definitely not by playing a Cher CD or hearing about Marty McFly’s adventures.  It is going back and pulling certain data for a specific time period based on the current date (or parameter).  In this article I will start with the easiest of year, then move onto month and week.

In all of my examples, I am going to use a fictitious date of {Hire Date} and using the CurrentDate function that is built in Crystal (the current date could be replaced by a parameter).  Also, all of my coding will go in as part of the record selection formula.

Let us start with year and imagine the CurrentDate is 2/1/2008.

Year({HireDate}) = Year(CurrentDate) – 1

                             = 2008 – 1

                             = 2007

The Year of the CurrentDate would end up being 2007 getting us all the {HireDates} from the previous year.

Now let us move onto the month.  This one will have to work a little bit differently because we have to take the month into consideration (if the month is January (01) we cannot necessarily subtract 1 like we did for the year because there is no month 0).  In order to fix this and solve we will use the DateAdd function that Crystal makes available for us.  Let us imagine that the CurrentDate is 1/14/2008.

Year({HireDate}) = Year(dateadd(‘m’,-1,CurrentDate)) and

Month({HireDate}) = Month(dateadd(‘m’,-1,CurrentDate))

                            =Year(12/14/2007) = 2007

                           =Month(12/14/2007) = 12

Now finally depending how your weeks are calculated you could have a couple of different selection formulas.  We will use the assumption that the week begins on a Sunday and that January 1 is the start of the first week for January and contains no December dates.  Let us imagine that the CurrentDate is 1/3/2003.

DatePart(‘ww’,{HireDate}) = DatePart(‘ww’,dateadd(‘ww’,-1,CurrentDate)) and

Year({HireDate}) = Year(dateadd(‘ww’,-1,CurrentDate))

                                          = DatePart(12/27/2002) = 52

                                         = Year(12/27/2002) = 2002

Go to Top  |  Return to Newsletter Contents

The Result Data Newsletter is published approximately once a month to share the latest information on business intelligence, data management and CRM. There should be a link below to allow you to change or remove yourself from our list. We take your requests very seriously. If you have any difficulty please contact us at 614-505-0770 and we will make sure that your request is handled properly. This is not intended to be an unsolicited message and you can reach us in person if needed.

© Copyright 2007 Result Data Consulting, Ltd. - All Rights Reserved
All trademarks and copyrights are the property of their respective owners. This information is provided without warranty.
Announcements
Quarter 1 Training Special
Schedule and attend any public training class now through March 31st and receive 10% off the normal class price OR opt for a gift certificate to the Apple Store for that same dollar amount. Restrictions apply and you must mention the promotional code Apple08 at the time of registration to receive the promotion.  Call 614-505-0770 for further details and restrictions.
Learn About Microsoft SharePoint and eCopy
Learn how SharePoint and eCopy make a great team for document management from the experts at Result Data and Gordon Flesch.  Attend our free seminar on March 6, 2008.  Call 614-505-0770 or click here to reserve your seat.
Cleveland Roadshow - Calming the Storm
See how solutions from Business Objects can help you gain control over the storm of information surrounding your business.  This event will be held on Mar. 4, 2008 at the Embassy Suites Beachwood hotel.  Call 614-505-0770 or click here for more information and to reserve your seat.
Microsoft SQL Server User Group
Join us for the Spring Microsoft SQL Server User Group meeting on March 28th. Our main presentation will be by Luis Gonzalez of Microsoft demonstrating and discussing the new and exciting features in SQL Server 2008.  Call 614-505-0770 or click here for more information and to reserve your seat.
Looking for a Few Good Men and Women
Join our award winning team of Business Intelligence consultants and .Net Software developers.
Send your resume and salary requirements to:
jobs@resultdata.com