3
votes

thanks for helping in advance. I am just starting out so I may be doing this entirely the wrong way

OK the problem is that the date value 2012, 2, 13 (2012 Feb 13) in PHP when called in the DatePicker is interpreted as 2012 March 13 because 2 means the third month when starting form 0 is March, I got that much.

//Getting the Min Date from the Datetime field

    $sqlmin = "Select min(datetime) from table1";
    $resultmin = mysql_query($sqlmin);
    $mindate = mysql_fetch_array($resultmin);
    $datetime1 = date('Y, n, j', strtotime($mindate[0])); //this will give me 2012, 2, 13 (Feb)

Now in the JS part


    $(function() {
       $( "#fromdate" ).datepicker({
       dateFormat: 'yy-mm-dd',
       minDate: new Date( php echo $datetime1; ),  // this thinks it is March but i want Feb

So the question is how can I get the month to be Feb instead of March in the Datepicker?

3
I thought about that but how do i subtract only the MONTH by 1? - Manish Pradhan

3 Answers

1
votes

Use this format instead: "F j, Y, g:i a"

Refs.: http://www.php.net/manual/en/function.date.php#example-665

$datetime1 = date("F j, Y, g:i a"); // March 10, 2001, 5:16 pm

That is one of the JavaScript expected formats.

minDate: new Date("<?php echo $datetime1; ?>")
0
votes

Just change the new Date function:

minDate: 
$(function() {
   var phpDate = new Date( php echo $datetime1; );
   $( "#fromdate" ).datepicker({
   dateFormat: 'yy-mm-dd',
   minDate: phpDate.setMonth(phpDate.getMonth() - 1),

getMonth will return 0-11, and setMonth will use that correctly.

0
votes

I managed to solve the "wrong month" thing by creating a list of month names:

$(function() {
                $( "#alkupvm" ).datepicker({
                    dateFormat:"yy-mm-dd", 
                    firstDay:1, 
                    dayNamesMin:["Su","Ma","Ti","Ke","To","Pe","La"],
                    monthNames:["Tammikuu", "Helmikuu", "Maaliskuu", "Huhtikuu", "Toukokuu", "Kes&auml;kuu", "Hein&auml;kuu", "Elokuu", "Syyskuu", "Lokakuu", "Marraskuu", "Joulukuu"],
                    minDate:"-2y",
                    stepMonths: 1,
                    maxDate:"+2m"

                    });
                });

Here specifically the monthNames list/array. Now the month shows up correctly.