The Official Salesforce Blog

The Official Salesforce Blog

Calculating Day of the Week

Eric Bezar Sep 18, 2005

Day_of_weekHave you ever had a need to know the day of the week an opportunity closed? What about excluding Saturdays and Sundays from your reports so that your dashboards only show business days?

Day of week calculations are easy with formula fields, using the technique described below.

This example calculates the day of the week as a number (0 = Saturday, 1 = Sunday, 2 = Monday, 3 = Tuesday, etc.) for Opportunity Close Date.

Formula Return Type:
Number

Formula:
MOD( {!CloseDate} - DATE(1900, 1, 6), 7)

Remarks: 

  • This formula works by picking a known Saturday (January 6, 1900 in the example), subtracting it from the provided date, and using MOD to divide the result by 7 and return the remainder. Thanks to Simon W. and Jesse C. for this example.
  • Exclude Saturday & Sunday from reports by adding a report selection criteria of "Day of Week greater than 2".
  • A text version of this formula could spell out the day of the week:

CASE(MOD( {!CloseDate} - DATE(1900, 1, 6), 7), 0, "Saturday", 1, "Sunday", 2, "Monday", 3, "Tuesday", 4, "Wednesday", 5, "Thursday", 6, "Friday","")

 

4 Comments

Clive Churchward

How do you calculate the day of the week from a (date & Time) field ?

and

Can I calculate a delivery period to exclude weekends ie Collect Friday, Delivered Tuesday = 2 Days and again my date
fields would contain Date+Time ie
28/10/05 10:00
01/11/05 11:15

Ryan McGinn

Will this get thrown off on leap years?

Thanks,
Ryan

rachael

can each day of the month be calculated as a number?

Paul

This formula doesn't properly handle Daylight Savings Time. I noticed that if I build a report based of this type of field, and try to exclude Saturday and Sunday, values that fall between midnight and 1 AM are included anyways, which throws off the report (and subsequently, the pretty chart I'm looking to create).

Post a comment