Mohan Ram
Mohan Ram

Reputation: 8463

jQuery Date Picker Min Max date issue

<?php
$week_start_date = '2012-02-06';
$week_start_date = '2012-02-12';
?>

$("#test").datepicker({
    altField: "#test1",
    altFormat: "yy-mm-dd",
    autoSize: true,
    minDate: new Date("<?php echo $week_start_date; ?>"),
    maxDate: new Date("<?php echo $week_end_date; ?>")
});

OUTPUT

enter image description here

In my location(India) the range restriction seems display right. but in US the range shows from 2012-02-05 to 2012-02-11.

I dont know why its making restriction on day prior. i checked in the firebug the restriction range is right but in US the range is displaying as 2012-02-05 to 2012-02-11.

Please help me to solve this.

Upvotes: 0

Views: 2184

Answers (1)

nkm
nkm

Reputation: 5914

This happens when the same script is getting executed in two different places. Note that these script will be running at the user's browser, which make use of user timezone.

When you run minDate: new Date("2012-02-12"), the passed parameter used to calculate Date in local timezone. So if you are in IST, it will generate date for 2012-02-12, 50:30 and if you are in EST, it will generate 2012-02-11, 19:00.

Solution, generate Date object by full date and time values,

> d = new Date(2012,02,12,00,00,00)
=> Date {Mon Mar 12 2012 00:00:00 GMT+0530 (IST)}

Upvotes: 2

Related Questions