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
abinayaabinaya 

how to get the selected day in the given date range

Hi all,

How to get the selected day dates in the a given date range. For eg: i am selecting the date range from nov 1st to nov 30th. In this date range i want to get the monday date's i.e nov 2nd, nov 9th, etc.

Also i want to check a condition in soql like createddate day is equal to monday .

Kindly help me in this.

Regards,
Abinaya.

 
Best Answer chosen by abinaya
SRKSRK
You can do it using formula fiel like this


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


Note that this formula only works for dates after 01/07/1900. If you’re working with older dates, use the same process with any Sunday prior to your earliest date (e.g. 01/05/1800).
You can also adjust this formula if your week starts on a different day. For example, if your week starts on Monday, you can use January 8, 1900 in your condition. The new formula looks like this:


or you can us the same in apex code like this

date StartDate = date.newInstance(1900, 1, 8);
date Todaydate = system.today();
Integer numberDaysDue = startDate.daysBetween(Todaydate);
Integer x = math.MOD( numberDaysDue , 7 );

system.debug('$!@%#$!@%#'+ x);

like it return 1 as its tuesday 

All Answers

SRKSRK
You can do it using formula fiel like this


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


Note that this formula only works for dates after 01/07/1900. If you’re working with older dates, use the same process with any Sunday prior to your earliest date (e.g. 01/05/1800).
You can also adjust this formula if your week starts on a different day. For example, if your week starts on Monday, you can use January 8, 1900 in your condition. The new formula looks like this:


or you can us the same in apex code like this

date StartDate = date.newInstance(1900, 1, 8);
date Todaydate = system.today();
Integer numberDaysDue = startDate.daysBetween(Todaydate);
Integer x = math.MOD( numberDaysDue , 7 );

system.debug('$!@%#$!@%#'+ x);

like it return 1 as its tuesday 
This was selected as the best answer
pranab khatuapranab khatua
public class AccController {

    List<Account> accts = [Select name, phone,type, industry, fax from account];
    
    public List<Account> getAcct(){
        return accts;
    }
    
    public string getDate(){
    
       String value;
       date myDate = date.newInstance(1990, 11, 21);
       //value = String.ValueOf(myDate.format('EEEE'));
       
       Datetime dt = DateTime.newInstance(myDate, Time.newInstance(0, 0, 0, 0));

       value =dt.format('EEEE');
       Map<Integer, String> month = new  Map<Integer, String>();
       month.put(1, 'Jan');
       month.put(2, 'Feb');
       month.put(3, 'Mar');
       month.put(4, 'Apr');
       month.put(5, 'May');
       month.put(6, 'Jun');
       month.put(7, 'Jul');
       month.put(8, 'Aug');
       month.put(9, 'Sep');
       month.put(10, 'Oct');
       month.put(11, 'Nov');
       month.put(12, 'Dec');
       
       String mn = month.get(myDate.month());
       
       
       //value = string.valueOf(myDate.month()) + '\n';
       
       //value += string.valueOf(myDate.format()) + '\n';
       //value += string.valueOf(myDate.addMonths(3)) +  ' ';
       //value += string.valueOf(myDate.Day());
      // CASE(MOD( myDate  - DATE(1900, 1, 6), 7), 0, 'Saturday', 1, 'Sunday', 2,'Monday', 3, 'Tuesday', 4, 'Wednesday', 5, 'Thursday', 6,'Friday', '');
      
      value += ', '+ string.valueOf(myDate.Day()) + ' '+ mn +', '+ string.valueOf(myDate.year());
       return (value);
    
    }
}
SRKSRK
Hi Pranab,

Very usefull and nicely written code, thanks for the effort but i belive the question is getting  "selected day in the given date"
for example if i pass today date it return "Tuesday" as today is tuesday 

the code you have mentioned above will formate the data and chagne it to 24 Nov 2015 , if i enter 24/11/2015 as input 

i let me know if i miss undersatnd the question