Change Date Picker Automatically

I have a series of date pickers, one is for contract start, the next is contract end and then there is renewal date.

The two in relation to this thread are contract end and renewal date, and basically what I would like to happen is when the contract end selection is made, the renewal date date picker changes to 11 months ahead.

Was wondering if I could get some help with this please, this is what I got at the moment.

Contract End -

<script type="text/javascript">DateInput('contractEnd', true<?php if(isset($cEnd)){if (!empty($cEnd)){echo ",'YYYY-MM-DD', '$cEnd'";}}?>)</script>

Renewal Date -

<script type="text/javascript">DateInput('renewalDate', true<?php if(isset($rDate)){if (!empty($rDate)){echo ",'YYYY-MM-DD', '$rDate'";}}?>)</script>

So just to recap, after selecting the ‘contract end’ date picker, the ‘renewal date’ is exactly changed to 11 months in the future.

Thanks in advance

Hi,

Can you provide a demo (e.g. JSFiddle) of it not working?

Check this one plz
http://jsfiddle.net/f4s46bvq/1/ then we can move to month

Morning Pullo, am trying to get it into jsfiddle, but am all sorts of problems, because of the way its set out.

There a file with it called calendarDateInput.js to allow for the automatic date picker via the calendar.

Will keep trying

Hi sunny, I can see what your doing yes, and have just chatted with the admin guy using it and he happy to input the date himself rather than using the datepicker method.

We are based in the UK, so the date method the admin guy would use would be for example: 03/11/2015

DD/MM/YYYY

If you can provide a demo that demonstrates your problem, I’m happy to have a look.

Ok have put a file together aside from the main project and this is where it is -

js project

Cool.
My first question is: is there any reason for not using the jQueryUI datepicker?
It has a well documented API and facilitates such things as making one datepicker dependant on another.

No reason at all Pullo, other than pure ignorance lol

Hey,

Using jQueryUI’s datepicker, you can do it like so:

<p>
  <label for="endDate">End date</label>
  <input type="text" readonly="readonly" id="endDate" />
</p>
<p>
  <label for="renewalDate">Renewal date</label>
  <input type="text" readonly="readonly" id="renewalDate" />
</p>

$("#endDate").datepicker({
    dateFormat: "dd/mm/yy",
    onSelect: function(dateText, instance) {
        date = $.datepicker.parseDate(instance.settings.dateFormat, dateText, instance.settings);
        date.setMonth(date.getMonth() + 11);
        $("#renewalDate").datepicker("setDate", date);
    }
});
$("#renewalDate").datepicker({  
    dateFormat: "dd/mm/yy"
});

DEMO

Hi Pullo,

I just got around to finishing that off, and wanted to say thank you again for the help, it works perfectly. :wink:

1 Like

Sorry guys, a little error has popped up to do with the datepicker and by the looks the way the date is formatted -

Array ( [0] => Array ( [0] => 42000 [SQLSTATE] => 42000 [1] => 8114 [code] => 8114 [2] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Error converting data type varchar to numeric. [message] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Error converting data type varchar to numeric. ) )

This is what I got

<input type="text" readonly id="endDate" name="contractEnd1" value="<?php echo $cEnd1; ?>" />

<script>
$("#endDate").datepicker({
dateFormat: "yy/mm/dd",
onSelect: function(dateText, instance) {
    date = $.datepicker.parseDate(instance.settings.dateFormat, dateText, instance.settings);
    date.setMonth(date.getMonth() + 11);
    $("#renewalDate").datepicker("setDate", date);
}
});
$("#renewalDate").datepicker({  
dateFormat: "dd/mm/yy"
});
$("#startDate").datepicker({  
dateFormat: "dd/mm/yy"
});
</script>

The field in the database is set to ‘date’ if that helps, and for example is saved as yyyy/mm/dd, although the code above is formatting it as dd/mm/yy but I tried changing the code above to yyyy/mm/dd and the same error popped up.

And this is the update code below, which I believe it pretty standard

$cStart1b=$_POST['contractStart1'];
$cEnd1b=$_POST['contractEnd1'];
$rDate1b=$_POST['renewalDate1'];

$query="update Intranet set Contract_Start='$cStart1b',Contract_End='$cEnd1b',Renewal_Date='$rDate1b' where ID=$sr";

The error has changed now, and I cant seem to work out how to fix it.

Its when I ‘Insert’ and ‘Update’ the contract that the error below appears -

Error in executing query.
Array ( [0] => Array ( [0] => 42000 [SQLSTATE] => 42000 [1] => 8114 [code] => 8114 [2] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Error converting data type varchar to numeric. [message] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Error converting data type varchar to numeric. ) )

Do I convert the date selected by the user via the datepicker tool before I insert or update or is it to do with something else.

I tried changing it to below, but didn’t work either -

$cStart1b=date('Y-m-d', strtotime($_POST['contractStart1']));
$cEnd1b=date('Y-m-d', strtotime($_POST['contractEnd1']));
$rDate1b=date('Y-m-d', strtotime($_POST['renewalDate1']));

Can you please export the table structure, and post that here for us to take a look at?

You can do that in PHPMyAdmin for example from Export → Custom and select Structure only.

Hi Paul,

I’m using SQL Server Management Studio and can’t see how to export the whole table, but below is the three fields associated with the date fields -

Contract_Start (date, null)
Contract_End(date, null)
Renewal_Date(date, null)

Hopefully that’s what your looking for

Use Google : )
After approx 10 seconds of Googling, I found this:

http://stackoverflow.com/questions/7052757/how-to-export-sql-server-database-structure-into-text-format

That’s why you’re paid the big bux :slight_smile:

sorry guys :relaxed:

I’m paid big bucks?