admin管理员组

文章数量:1313822

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;
    })

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;
    })
Share Improve this question edited Nov 15, 2013 at 12:58 greg asked Nov 13, 2013 at 21:47 greggreg 1642 silver badges11 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8
var d = new Date( date );
d.setMonth( d.getMonth( ) - 1 );

本文标签: javascriptjQuery Datepicker output formatted date minus 1 monthStack Overflow