0
<?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.

Mohan Ram
  • 8,345
  • 25
  • 81
  • 130
  • Timezone issue? Pushing to the timezone in the US from your time might be causing the days to jump one back? :/ – Chris Kempen Feb 04 '12 at 07:41
  • yes. how to solve this. i need universally to display the range in a right way – Mohan Ram Feb 04 '12 at 08:02
  • Have you checked out [this question](http://stackoverflow.com/questions/7754740/jquery-datepicker-formatdate-and-timezone-offset), [this question](http://stackoverflow.com/questions/2138208/jquery-ui-datepicker-and-timezones), or [this question](http://stackoverflow.com/questions/5398931/jquery-date-picker-timezone-issue)? – Chris Kempen Feb 04 '12 at 08:10

1 Answers1

2

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)}
nkm
  • 5,844
  • 2
  • 24
  • 38
  • I had gn start date as new Date(2012,01,30,00,00,00); and end date as new Date(2012,02,5,23,59,59); – Mohan Ram Feb 04 '12 at 10:21
  • In javascript month starts with 0, Jan is represented as 0, feb as 1 and so on. So with above date you are trying to create 30th Feb 2012, which doesn't exist and hence pointing to 1st March 2012. Try `new Date(2012,00,20,00,00,00)` – nkm Feb 04 '12 at 10:34