Find Day of selected Date on VF Page

Requirement: Find the day of selected date in date field

Solution:


public class DayOfDate {
    Private Date startDate = date.newInstance(0001, 1, 1);
  
    Public Date selectedDate{get;set;}
    public String dayValue{get;set;}
    public Account acc {get;set;}
    public DayOfDate()
    {  
        system.debug('startDate***'+startDate);
        selectedDate = date.today();
        system.debug('selectedDate*****'+selectedDate);
        acc = new Account();
    }

    public void calculateDayOfDate()
    {
        List<String> listDay = new List<String>{'Saturday' , 'Sunday' , 'Monday' , 'Tuesday' , 'Wednesday' , 'Thursday' , 'Friday'};
        selectedDate = acc.SLAExpirationDate__c;
        Integer remainder = Math.mod(startDate.daysBetween(selectedDate) , 7);
        system.debug('remainder____'+remainder);
        dayValue = listDay.get(remainder);
         system.debug('dayValue*******'+dayValue);
    }



}


VF Page Code:

<apex:page controller="DayOfDate" sidebar="false" showHeader="false">
  <apex:form >
  <apex:pageBlock >
      
      <apex:pageBlockSection columns="1">
          <apex:pageBlockSectionItem >
              <apex:outputLabel value="Enter Date"></apex:outputLabel>
              <apex:inputField value="{!acc.SLAExpirationDate__c}"/>
          </apex:pageBlockSectionItem>
          <apex:pageBlockSectionItem >
              <apex:outputLabel value="Day is : {!dayValue}" id="opID"></apex:outputLabel>
          </apex:pageBlockSectionItem>
          <apex:commandButton action="{!calculateDayOfDate}" value="Find Day" reRender="opID"/>
          
      </apex:pageBlockSection>
  </apex:pageBlock>
  </apex:form> 
</apex:page>


               




Thanks,
Sumit Shukla

Comments

Popular posts from this blog

Salesforce Spring 16 Release Exam (Maintenance Exam Q&A) for Developer 201 Admin

Show Hyper Link On Add Error in Salesforce Trigger

Show the Success Message before Redirecting the Detail page on Visualforce Page