+ Start a Discussion
Faizan Ali 24Faizan Ali 24 

Date navigation help

Hi all,

I am new to Salesforce and would appreciate if someone could help me with the following.

I want to move today's date forward (on click of button) whenever a certain number is selected from my picklist.

User-added image

So If I select 1 week and click the forward button it should go forward 1 week. If I click the back button it should go back 1 week. This applies to all the picklist values.

VF page code:

<apex:page showHeader="false" controller="increment">
    <apex:form>    
    
    <apex:outputText value="{0, date, dd/MM/yy}">
        <apex:param value="{!NOW()}" />
    </apex:outputText>
    
        <apex:commandButton value = "<"/>
        <apex:commandButton value = ">"/>
        
        <apex:selectList value="{!weeks}" size = "1">
            <apex:selectOptions value="{!items}">
            </apex:selectOptions>            
        </apex:selectList>
    
    </apex:form>   
</apex:page>


Apex class increment:

public class increment {
    String[] weeks = new String[]{};

    public PageReference test() {
        return null;
    }

    public List<SelectOption> getItems() {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('1 week','1 week'));
        options.add(new SelectOption('2 weeks','2 weeks'));
        options.add(new SelectOption('3 weeks','3 weeks'));
        options.add(new SelectOption('4 weeks','4 weeks'));

        return options;
    }

    public String[] getWeeks() {
        return weeks;
    }

    public void setWeeks(String[] weeks) {
        this.weeks = weeks;
    }
}

 
ANUTEJANUTEJ (Salesforce Developers) 
Hi Faizan,

>> https://developer.salesforce.com/forums/?id=9062I000000gAUKQA2

I see that there is an implementation in the lightning component that changes the second date input field which calls a function on change in the first date field.

I think it would be better in case if a lightning component is used.

Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.  

Thanks.