Activity Forums Salesforce® Discussions How Can I Tell the Day of the Week of a Date in Salesforce?

  • shariq

    Member
    September 22, 2018 at 11:27 am

    Formulas:

    There isn’t a worked incapacity to do this for you, yet you can make sense of it by checking the days since a date you know. Here’s the idea: I realize that June 29, 1985, was a Saturday. In case I’m endeavoring to make sense of the day of the seven day stretch of July 9 of that year, I subtract the dates to (Pivotal Training) determine the number of days (10) and then use modular division to figure to remove all the multiples of 7. The remainder is the number of days after Saturday (1 = Sunday, 2 = Monday, etc.) and you can use that number in your logic:

    MOD(DATEVALUE( Date_Field__c ) – DATE(1985,7,1),7)

    Apex Code

    You could do the same thing with time deltas, but you can also use the poorly documentedDateTime.format() function:

    // Cast the Date variable into a DateTime

    DateTime myDateTime = (DateTime) myDate;

    String dayOfWeek = myDateTime.format(‘E’);

    // dayOfWeek is Sun, Mon, Tue, etc.

  • Parul

    Member
    September 22, 2018 at 11:49 am

    There are two popular formulas that you can use to find the day of the week for a given date. You should be careful when you use these formulas, though, because they only work for the Gregorian calendar. (People in English-speaking countries used a different calendar before September 14, 1752.)

    Zeller's Rule

    The following formula is named Zeller's Rule after a Reverend Zeller. [x] means the greatest integer that is smaller than or equal to x. You can find this number by just dropping everything after the decimal point. For example, [3.79] is 3. Here's the formula:

    f = k + [(13*m-1)/5] + D + [D/4] + [C/4] - 2*C.

     

    Thanks

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos