im trying to use two date picker in a page. it seems to worked fine but after clicked on the submit button the date entered is not the same as the choosen date. both of the date inserted to the database is 01-01-1970.
how can i fix this?
<div class="form-group">
<label class="control-label col-sm-4">Date Issued</label>
<div class="col-sm-5">
<input class="form-control" type="text" id="dateIssuedpc" name="dateissued" required class="form-control" placeholder="Enter Date Issued"/>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-4">Date Expired</label>
<div class="col-sm-5">
<input class="form-control" type="text" id="dateExpiredpc" name="dateexpired" required class="form-control" placeholder="Enter Date Expired" />
</div>
</div>
<script>
$( function() {
$( "#dateIssuedpc").datepicker({
dateFormat: "dd-mm-yy",
changeMonth: true,
changeYear: true
});
$( "#dateExpiredpc" ).datepicker({
dateFormat: "dd-mm-yy",
changeMonth: true,
changeYear: true
});
} );
</script>
if field data type in database is datetime then
$dateexpired = $_POST['dateexpired'];
$new_dateexpired = date("Y-m-d H:i:s",strtotime($dateexpired));
$dateissued = $_POST['dateissued'];
$new_dateissued = date("Y-m-d H:i:s",strtotime($dateissued));
if field data type is date then
$dateexpired = $_POST['dateexpired'];
$new_dateexpired = date("Y-m-d",strtotime($dateexpired));
$dateissued = $_POST['dateissued'];
$new_dateissued = date("Y-m-d",strtotime($dateissued));
This is not datepicker problem, rather problem is with PHP code.
Mysql date format is always YYYY-MM-DD HH:II:SS
So while inserting data to mysql table, you have to convert the format for mysql
Ex:
$postDate = $_POST['date'];// just collect value from post fields.
$date = date("Y-m-d H:i:s",strtotime($postDate));
You need to format your date properly. First of all change format from dateFormat: "dd-mm-yy", to *dateFormat: "dd-mm-yyyy",* to better recognise year.
After that from php side you something like this
$dateissued = date("Y-m-d", strtotime($_POST['dateissued']) ); //MySql date format
Related
My datepicker works, at first! But if i'm checking the value of the input (with the datepicker) the value always is Null. The right value is displaying and an alert shows the right date. But in my php file i just retrieve null
<form action="" method="post">
<div class="flex-grid fg-step-1">
<div class="col col-medium-6 col-small-12 ">
<p style="margin-bottom: 20px;">Date Start</p>
<input type="text" id="dateStart" name="dateStart" class="datepicker">
</div>
<div class="col col-medium-6 col-small-12 ">
<p style="margin-bottom: 20px;">Date End</p>
<input type="text" id="dateEnd" name="dateEnd" class="datepicker">
</div>
</div>
<input type="submit" class="main_btn"">
</form>
jQuery(document).ready(function(){
jQuery('#dateEnd').prop('disabled', true);
jQuery( '#dateStart' ).datepicker({
changeMonth: true,
changeYear: true,
showAnim: "slideDown",
dateFormat: "yy-mm-dd",
minDate: 0,
onSelect: function(selectedDate){
jQuery('#dateEnd').datepicker('option', 'minDate', selectedDate);
jQuery('#dateEnd').prop('disabled', false);
alert(selectedDate);
}
});
jQuery( '#dateEnd' ).datepicker({
changeMonth: true,
changeYear: true,
showAnim: "slideDown",
dateFormat: "yy-mm-dd",
onSelect: function(selectedDate){
alert(selectedDate);
}
});
})
<?php
if ( $_POST['dateStart'] == Null ) {
$dateStart = false;
$in_date_start = "";
} else {
$in_date_start = $_POST['dateStart'];
}
if ( $_POST['dateEnd'] == Null) {
$dateEnd = false;
$in_date_end = "";
} else {
$in_date_end = $_POST['dateEnd'];
}
?>
The Problem is, that we are using WordPress and using our own Theme. I need a solution for retrieving the selectedDate in my php-code
You can use hidden field :
1) get date and set in hidden field {with JS} and retrieve date from hidden field in php { at form submission }
I am using a Codeigniter script purchased in Codecanyon. I need add the input datepicker but in Controller cannot get from UI picked date.
UI:
<input type="date" class="form-control datetimepicker" value="<?php echo date('Y-m-d'); ?>" name="deadline" id="deadline">
Controller :
$deadline = date("Y-m-d", strtotime($this->input->post('deadline')));
I have test to show before update database but it's display current time:
var_dump($deadline);
return;
The modal you're dealing with is outside the form. I made it that - using jquery - when the date field is changed, it updates the value of its hidden field which is in the form. So when the modal triggers form submission, the value of its date field is also submitted to the controller.
HTML:
<input type="hidden" name="deadline" id="deadlinehidden" value="" />
JS:
$("#deadline").on("change paste keyup", function() {
$("#pos-sale-form input[name='deadline']").val($(this).val());
});
you can use this:
<input name="deadline" type="text" value="2017-07-08" class="form-control datepicker" id="datepicker">
<script>
$( function() {
$( "#datepicker" ).datepicker();
} );
</script>
$date=$this->input->post('deadline');
I'm a newbie in this php and html. I'm developing a laundry system using php with mysql. right now, users can just enter whatever date they want for pickup and delivery.. for example, today is 10 feb 2018, user key in 9 feb 2018 as pickup. that should not be possible. how do i handle that? my html are
<font face="Arial Black">Pickup date:</font>
<input type="date" name="pickupdate">
The below snippet is from one of my projects, see if this helps you in anyway:
The HTML Code:
<label for="from">From</label>
<input type="text" id="from" name="from"/>
<label for="to">to</label>
<input type="text" id="to" name="to"/>
The Javascript Code:
var dateToday = new Date();
var dates = $("#from, #to").datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 3,
minDate: dateToday,
onSelect: function(selectedDate) {
var option = this.id == "from" ? "minDate" : "maxDate",
instance = $(this).data("datepicker"),
date = $.datepicker.parseDate(instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings);
dates.not(this).datepicker("option", option, date);
}
});
I am using bootstrap datepicker
here is my code
var available_Dates = ["2015-08-05","2015-08-16","2015-08-21"];
$('input.date-pick').datepicker({
language: 'en',
beforeShowDay: function(date){
var formattedDate = $.fn.datepicker.DPGlobal.formatDate(date, 'yyyy-mm-dd', 'en');
if ($.inArray(formattedDate.toString(), available_Dates) == -1){
return {
enabled : false
};
}
return;
}
});
Html i am using
<div class="form-group">
<label><i class="icon-calendar-7"></i> Select a date</label>
<input class="date-pick form-control" placeholder="Jul 18, Sat" data-date-format="M d, D" type="text">
</div>
Now the problem is, the result comes with an additional day.
2015-08-06
2015-08-17
2015-08-22
But i want selected date to be the result.
Please provide suggestion,
Thank you
How do I get my date to display like this: "yy-mm-dd" inside my date input textbox after I have selected a date?
Information is reading from a database.
So I need it saved in a database again.
JavaScript:
<script>
$(document).ready(function() {
$("#from").datepicker();
});
</script>
Html code:
<div class="field">
<label>Date</label>
<input type="text" name="date" value="<?php value('date'); ?>" id="from" />
<?php if(isset($errors['date'])) { ?>
<div class="error"><?php echo $errors['date']; ?></div>
<?php } ?>
</div>
Things that I have tried:
http://docs.jquery.com/UI/Datepicker#option-dateFormat
http://docs.jquery.com/UI/Datepicker/formatDate
jQuery UI DatePicker - Date Format
jquery ui datepicker date format
Define the format during initialization
$("#from").datepicker({
dateFormat: 'yy-mm-dd'
});
The value is updated as well. See an example.