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
nothingnothing 

getting day of the week

Is it possible to get the day of the week ("Friday") from Date or DateTime?

Thanks in advance
dmsx2dmsx2

The most common way to do this (using SFDC formulas - you may have to alter this a bit for Apex) is to use a MOD function:

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

Hope this helps.

jf317820jf317820
is there no instance method for this?
sum3sum3

i don't think there's a method.  here's an apex version of the SFDC code posted.

Date dueDate = System.today();
Date refDate = Date.newInstance(1900, 1, 7);  // Jan 7 1900 = Sun

// 0 = Sun ... 6 = Sat
Integer dayOfWeek = Math.mod(refDate.daysBetween(dueDate), 7);

Mike Baran 6Mike Baran 6
Given a date "a_date", use the datetime formatter to return the result you want.

String day_of_week = a_date.format('E');

day_of_week will now be 'Sun' or 'Mon' or 'Tue' or 'Wed' or 'Thu' or 'Fri' or 'Sat'