Reputation: 177
I am using jquery full calendar to show some booking details. I am inserting date into the database in ("yyyy-MM-dd")
format.
But when i retrieve the title value from the calendar using var title=$("#calendar").fullCalendar('getView').title;
it output as "June 2015". later i am using these two days for a comparison. Therefor i need to either send date into the database in "19 June 2015" format or convert title date value into "06 2015".
If anyone has a clear idea about this help me. Hope the problem is clear. I am using codeignier and i use the following cotroller method to send the data into the database.
function add_reservation() {
$reservation_model = new Reservation_model();
$reservation_service = new Reservation_service();
$reservation_model->set_date_cal(trim($this->input->post('date', TRUE)));
// $reservation_model->set_date(strtotime($this->input->post('date', TRUE)));
$reservation_model->set_title(trim($this->input->post('selected_hall', TRUE)));
$reservation_model->set_type(trim($this->input->post('selected_time', TRUE)));
$reservation_model->set_description(trim($this->input->post('name', TRUE)));
$reservation_model->set_advanced_payment_status(trim($this->input->post('optionsRadios', TRUE)));
//$reservation_model->set_advanced_payment_status(trim($this->input->post('no', TRUE)));
$reservation_model->set_paid_amount(trim($this->input->post('paid_amount', TRUE)));
$reservation_model->set_fax(trim($this->input->post('fax', TRUE)));
$reservation_model->set_telephone_number(trim($this->input->post('telephone', TRUE)));
$reservation_model->set_address(trim($this->input->post('address', TRUE)));
$reservation_model->set_menu_no(trim($this->input->post('selected_menu_number', TRUE)));
$reservation_model->set_menu_price_per_plate(trim($this->input->post('menu_price', TRUE)));
$reservation_model->set_is_deleted('0');
$this->db->last_query();
echo $reservation_service->add_reservation($reservation_model);
}
basically i want to change the format of the date which i am sending to the database as "19 June 2015"
Upvotes: 0
Views: 847
Reputation: 11310
Considering your the date you have as 2015-06-19
and your DB Date as June 2015
<?php
$date = "2015-06-19";
$month = date("F", strtotime($date));
$year = date("Y", strtotime($date));
$MyDate = $month.' '.$year;
$MyDBDate = "June 2015";
if ($MyDate == $MyDBDate)
{
# Your Action Here
}
You can change the condition or dates according to your need.
Here's the EVAL Link for you
Update :
Updated with Javascript version to compare as per OP's Request
<script>
var MyDate = "<?php echo $MyDate?>";
var MyDBDate = "June 2015";
if (MyDate ==MyDBDate)
{
alert('Match');
} else {
alert('Not a Match');
}
</script>
Upvotes: 0
Reputation: 1545
Don't change the MySQL format. Change your html OR keep every thing the same way it is now and use javascript to convert it to mysql format.
var title=$("#calendar").fullCalendar('getView').title; // "June 2015"
var d = new Date(title);
var title = d.getFullYear() + "-" +( d.getMonth() + 1); // "2015-6"
Now, you can compare. Let me know, if you are looking for something else.
Upvotes: 1
Reputation: 169
Format date
$newDate = date('d F Y',strtotime($_POST['date']));
FROM Database SQL
DATE_FORMAT(DateValueDb,'%d %b %Y')
Upvotes: 0