I am using codeigniter and doctrine.php and I am stuck at this place where when I don't select any value from datepicker it should submit null value in database, but its sending yesterdays date everytime instead.
function initDatePicker(datePickerID, dateInput){
$( "#" + datePickerID )
// Initializing the datepicker
.datepicker()
// Detecting the on change date event
.on('changeDate', function (data) {
var date = new Date(data.date);
var dateString = date.getDate() + '-' + parseInt(date.getMonth() + 1) + '-' + date.getFullYear();
$("#" + dateInput).val(dateString);
});
}
Controller
$salesOrder->setDateOfBilling($post_data['date_of_billing']);
if($date_of_billing)
{
$salesOrder->setBillingStatus("Paid");
}
else
{
$salesOrder->setBillingStatus("Not Paid");
}
$salesOrder->setDateOfPayment($post_data['date_of_payment']);
$em->persist($salesOrder);
$em->flush();
Model
/**
* @Column(type="datetime", nullable=true)
*/
protected $date_of_billing;
public function getDateOfBilling()
{
return $this->date_of_billing;
}
public function setDateOfBilling($date_of_billing)
{
$this->date_of_billing = new \DateTime($date_of_billing);
}
View This is the form where I use date picker
<div class="form-group">
<label class="col-sm-4 control-label">Date of Billing</label>
<div class="col-sm-5">
<input type="text" name="date_of_billing" id="date_of_billing" class="form-control" placeholder="Date Of Billing"
readonly>
<div id="billing_date_picker"></div>
</div>