function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
TinkuTinku 

syntax to know the day of the week

What is the syntax to know the Day of the week.

 

And also to subtract one date field with Today's date.

 

the requirement is like this:

 

If(Today=Friday)

{

  if( (account.createdDate - Today) > 21 || (Today - account.CreatedDate) >21 )

  {

    Create case;

  }

}

 

I need the help with the Blue Link part.

MLamb2005MLamb2005

This will get you the day of the week, based on a date (where TimeDate__c is your date field): 

 

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

 

Dates subtract just like any other field, something like: Today() - TimeDate__c

TinkuTinku

this is to write inside the apex trigger code.

 

When i wrote Today() - account.CreatedDate inside the apex trigger.

 

It gives me this error:

Compile Error: Method does not exist or incorrect signature: TODAY()

 

MLamb2005MLamb2005

Try System.today(). 

 

Failing that you can use Datetime dt = System.now(); to return a datetime object, but I'm not entirely sure if you can subtract from that directly. Check out the Apex Code documentation (http://www.salesforce.com/us/developer/docs/apexcode/index.htm) and search for "datetime" for more information on the methods available.

 

 

bob_buzzardbob_buzzard

You can get the day of the week from a DateTime field by executing the format method with the appropriate pattern,

 

 

E.g. to get the day of the week as Mon, Tue etc

 

 

DateTime dt=System.now();
String dowStr=dt.format('EEE');

 

 

 

TinkuTinku

Bob.

 

What is 'EEE' in your syntax? Do i have to write Monday instead of EEE? or is it the syntax?

TinkuTinku

How to subtract one date from another?

bob_buzzardbob_buzzard

EEE is the replacement pattern for day of the week.  If you use the code today (Friday) you will get "Fri" in the string.  The replacement patterns are the same as those in the Java SimpleDateFormat class, information on which can be found at:

 

http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html

TinkuTinku

Thank you.