0

Page:

<apex:input value="{!startDate}" label="Start Date" id="date1"/>
<script>
$( document ).ready(function() {
    $.datepicker.setDefaults(
        $.datepicker.regional['en-GB']
    );
    $(function() {
        $( "[id$=date1]" ).datepicker();
        $( "[id$=date2]" ).datepicker();
    });
});
</script>

Controller:

public Date startDate {get;set;}   
public AttendanceView_AdvancedInputCont(ApexPages.StandardController controller){
        startDate = Date.newInstance(2016,8,31);
    }

I have tried to default the date in the constructor, however this doesn't format properly. (See below.) If I select a date it appears as 19/04/2016 as it should.

enter image description here

Is there a way to do this?

1

One way would be changing your startDate property to String instead of Date and later parsing it back to Date.

For example:

 public String startDate {get;set;}   
 public AttendanceView_AdvancedInputCont(ApexPages.StandardController controller){
        Date orginalDate = Date.newInstance(2016,8,31);
        startDate = orginalDate.format();
        }

Later, on setting new value from the page, you can change the string type to Date by

Date dateValue = Date.parse(startDate);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.