How to exclude weekends from total number of days in crystal report

By | August 25, 2020

In sage X3, we have a functionality of printing various types of reports such as Order, Invoice, Payments, and Receipt etc. This report is created by using crystal report. Crystal Report is a very powerful tool used to pull data from sage and present it in a ways you want.

Sometimes in crystal report, we may have to develop sales history report. The report should shows the Order No, Invoice No, order date, invoice date, shipment date and how many days it takes to ship an order from the day we received the order until the day it is invoiced. We may also want to calculate how many days early or late based on the date promised to the customer. If the deliveries won’t be done on weekends then in that case we may need to exclude the weekends from the number of days. Refer the below figure of report.

Sales History Report

We need to create two different formulas, one for calculating Days to ship and other for Days late.

Calculation Needed:

Days To Ship= Invoice Date – Order Date(exclude weekends)

Days Late= Invoice Date – Promise(Shipment) Date (exclude weekends)

Crystal report has a various types of built in function and operators that includes String function, math function, date and time function, date ranges, arithmetic ,conversion, array operators, etc. We may use that pre-defined function to perform various calculation etc. Some of the Date Time function are as follows:

Date and Time Function includes:

Current Date : This function display the current date.

Current Time: This function display the current time.

DayOfWeek(): This function diplays the day of the specified date.

Syntax: DayOfWeek(date)

DateAdd(): The DateAdd() function can be used to add an interval of time to a date.

Syntax: DateAdd(interval type,number,start date)

DateDiff():The DateDiff() function is used to calculate date difference between two dates.

Syntax: DateDiff(interval type,date 1,date 2)

DatePart(): The DatePart() function returns the part of a date such as a day, month and year.

Syntax: DatePart(date_part,input date)

Interval type description:

yyyy:   years

d:        Day

m:      month

w:      Weekday

ww:   Weeks

 q :     quarters

h:       hours

m:     minutes

s:       second

As we have to calculate here difference between two dates we will use DateDiff() function.

Crystal Formula to exclude weekends:

Set Variables for the fields to be used in the calculation.

Define the variable of datatype datetime to be used in the calculation i.e. d1 and d2.

Formula to calculate Days to Ship:

DateTimeVar d1:= {SORDER.ORDDAT};

DateTimeVar d2:={SINVOICE.ACCDAT};

DateDiff(“d”,d1,d2)-DateDiff(“ww”,d1,d2,crSaturday)- DateDiff(“ww”,d1,d2)

Formula to calculate Days Late:

DateTimeVar d1:= {SORDER.SHIDAT};

DateTimeVar d2:={SINVOICE.ACCDAT};

DateDiff(“d”,d1,d2)-DateDiff(“ww”,d1,d2,crSaturday)- DateDiff(“ww”,d1,d2)

Where “d” is no. of days

 “ww” is no. of weeks

  “crSaturday” is used to exclude all the saturday between  dates

   “crSunday” is used to exclude all the sunday between  dates

This blog help us to calculate the number of days between two different dates using date function i.e DateDiff() excluding the weekends.

About Us

Greytrix – a globally recognized and one of the oldest Sage Development Partner is a one-stop solution provider for Sage ERP and Sage CRM organizational needs. Being acknowledged and rewarded for multi-man years of experience, we bring complete end-to-end assistance for your technical consultations, product customizations, data migration, system integrations, third-party add-on development and implementation competence.

Greytrix caters to a wide range of Sage X3, a Sage Business Cloud Solution, offerings. Our unique GUMU™ integrations include Sage X3 for Sage, Dynamics 365 CRM and Magento eCommerce along with Implementation and Technical Support worldwide for Sage X3. Currently we are Sage X3 Implementation Partner in East Africa, Middle East, Australia, Asia, US, UK. We also offer best-in-class Sage X3 customization and development services, integrated applications such as POS | WMS | Payment Gateway | Shipping System | Business Intelligence | eCommerce and have developed add-ons such as Catch – Weight  and Letter of Credit and India Legislation for Sage X3 to Sage business partners, end users and Sage PSG worldwide.

Greytrix is a recognized Sage champion ISV Partner for GUMU™ Sage X3 – Sage CRM integration also listed on Sage Marketplace; GUMU™ integration for Sage X3 – Salesforce is a 5-star rated app listed on Salesforce AppExchange and GUMU™ integration for Dynamics 365 CRM – Sage ERP listed on Microsoft AppSource.

For more information on Sage X3 Integration and Services, please contact us at, We will like to hear from you.