Question

I am trying to do the following:

When selecting a date with the jquery datepicker, get the value as the same date but from previous month. Format as mmddyy

so if you select 11-13-2013, then it will return 10132013 as the value for the input field.

I managed to get the formatting, but not the previous month.

here is the script:

    $('#choose-date').change(function(){
    var date            = $(this).datepicker('getDate');
    var formatted_date  = $.datepicker.formatDate('mmddyy', date);
    window.location     = '/getpage.do?date=' + formatted_date;
    })

The field for the datepicker is a simple text input

Any thoughts?


This is the new finished script:

    jq$('#choose-date').change(function(){
        var date           = jq$(this).datepicker('getDate');
        var d              = new Date( date );
        d.setMonth( d.getMonth( ) - 1 );
        var formatted_date = jq$.datepicker.formatDate('mmddyy', d);
        window.location    = '/getpage.do?date=' + formatted_date;
    })
Was it helpful?

Solution

var d = new Date( date );
d.setMonth( d.getMonth( ) - 1 );
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top