Disable time picker in Datetime picker - php

I want to disable the time picker in datetime picker.I am using some parameters like pickTime: false and format: "dd MM yyyy" .But no use..i'm using from this http://eonasdan.github.io/bootstrap-datetimepicker/
<script type="text/javascript">
$(function () {
$('#datetimepicker1').datetimepicker();
format: "dd MM yyyy"
});
</script>
Plzz give a solution

Better to use this to get only Date and you also have multiple Options with it
Have a look at this
Bootstrap DatePicker

You can pick date with
$('#datetimepicker1').val()
or
$('#datetimepicker1').data('date')
This only gives the date value
Possible Duplicate of How to get the value of the date using Bootstrap Datepicker

You did some wrong in object passing into the function.
<script type="text/javascript">
$(function () {
$('#datetimepicker1').datetimepicker({
format: "dd MM yyyy"
});
});
</script>

It was your format string. 'yyyy' does not exist. It is 'YYYY' instead.
Also, dd would have gotten you the days like this: Su, Mo, Tu, ...
You probably wanted 01, 02, 03,...
Here's the documentation on the format:
http://momentjs.com/docs/#/displaying/format/

Possible solution:
$('#datetimepicker4').datetimepicker({
format: 'YYYY-MM-DD'
});
As answered by Celt in this post:
https://stackoverflow.com/a/28542910/2295862

Related

By default today's date in datepicker

I am using datepicker in my project. I want to select by default today's date, how would I do this?
You can do:
$("#datepicker").datepicker().datepicker("setDate", new Date());
use php date instead of js date (js uses system date - it will not correct at all)
$('.datepicker').datepicker('SetDate', '<?php echo date('y-m-d');?>');
Try this
$(".datepickclass").datepicker('setDate', new Date());
OR
$(function() {
$("#datepickerid").datepicker({
dateFormat: "yy-mm-dd"
}).datepicker("setDate", new Date());
});
OR
Set to today:
$('#datepickerid').datepicker('setDate', '+0');
For Bootstrap Datepicker
$('#dob').datepicker('setDate', new Date());
$('#dob').datepicker('update');
DEMO

Date field is being reset in PHP and MySQL

When I am trying to edit some fields in the form, the date is being reset to 01-01-1970 01:00:00 but its stores and retrieves its value from the database perfectly for the very first time. Then it's being reset when I edit some other fields except date.
Below my jQuery date picker:
<script>
$(document).ready(function(){
$("#policy_start_date").datepicker({
numberOfMonths: 1,
onSelect: function(selected) {
$("#policy_end_date").datepicker("option","minDate", selected)
}
});
$("#policy_end_date").datepicker({
numberOfMonths: 1,
onSelect: function(selected) {
$("#policy_start_date").datepicker("option","maxDate", selected)
}
});
});
</script>
POST DATA
$date_t=$_POST['policy_start_date'];
$datearr=explode('/',$date_t);
$month=$datearr[0];
$day=$datearr[1];
$year=$datearr[2];
$policy_start_date=$year."-".$month."-".$day;
//$policy_end_date = $_POST['policy_end_date'];
$date_t=$_POST['policy_end_date'];
$datearr=explode('/',$date_t);
$month=$datearr[0];
$day=$datearr[1];
$year=$datearr[2];
$policy_end_date=$year."-".$month."-".$day;
Usually this is happen because the format stored in db and the format sent/acceptable by datepicker.
Standard datepicker format is 09/03/2013 (m/d/y).
What is displayed on the textbox when you echoed the data?
1. 09/03/2013 (m/d/y)
or
2. 2013-09-13 00:00:00 (Y-m-d H:i:s)
if option one (1) is displayed, then we certain need to see the code that display the form you used.
if option two(2) is displayed, then you need to format it before echoing into the textbox.
use this,
$time = strtotime($date_stored_in_database);
$your_date = date('Y/m/d',$time);
The strtotime will convert the date you stored in database into UNIX TIMESTAMP, and date function will convert it to the format you needed.

Datepicker get date according to server date/time

How to make work datepicker according to server time , how to set the server time to datepicker Jquery Ui, any help will be appreciated
Yes via clinet side we cannot get the server datetime, is there any procedure to get the server date/time and apply to date picker in PHP?
<?php $_date=date("d-m-Y"); ?>
<input type="text" class="datepicker" name="_date" value="<?=$_date;?>"/>
hope this will help.
//In my case i have used folloing script. Hope it will help you!
$('#selectedPicker').datepick
({
yearRange: '1980:2010',
alignment: 'bottomRight',
onSelect: updateSelected,
altField: '#set_Date',
showTrigger: '#calImg'
}).datepick('setDate', '<?php echo $server_date; ?>');
Use this. It will work and set maxDate if possible so the greater date is not selected
$(function() {
$( "#ppcertdate" ).datepicker({ maxDate: "<?=date("d/m/Y");?>", dateFormat: 'dd/mm/yy' });
$("#ppcertdate").datepicker("option","defaultDate", "<?=date("d/m/Y");?>");
});

Retrieving and Comparing Dates using JQuery And PHP

I am using jQuery's datepicker in wordpress/PHP and I am using this code to show dates:
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(function() {
$("#datepicker").datepicker();
$("#datepicker").datepicker("option","dateFormat",'yy-mm-dd');
});
</script>
Date<input type="text" id="datepicker" size="20" maxlength="15" style="width: 80px;" readonly="readonly"/>
It successfully displays my date.
Also, I have a table (wp_redeem_vouchers) in the database that has specific voucher redemption dates saved in it:
id wp_deal_id redeem_date
1 Amazon6767 2012-03-21
2 Ebay87nm 2013-06-12
3 M&Svouc 2013-01-01
4 ASDA 2011-09-08
Question:
How can I retrieve "redeem_date" and compare with the datepicker's textbox date (upon selection) with the date already saved in the database?
Is there anyway I could disable past date so that user can't choose the past date from date picker? i.e The user on 14/03/2013 can't choose 22/02/2013 from datepicker.
For your i)
$('#datepicker').datepicker( {
minDate: 0,
onSelect: function(dateText, inst) {
$.ajax({
type: "POST",
url: "some.php",
data: { date: dateText },
onSuccess: function(e){
alert("success");
}
});
});
Then in the some.php file you do your compare with mysql and you return a success or failure getting the alert(success).
Then I would start with
$date = $_POST['date'];
die($date);
In the some.php just to see if it is passed correctly.
Well, you can pass your datepicker date string (adjust format to $("#datepicker").datepicker("option","dateFormat",'yyyy-mm-dd');) to following JavaScript function which creates a Date object:
function createDate(s) {
var bits = s.split('-');
var d = new Date(bits[0], bits[1] - 1, bits[2]);
return d;
}
Then you have to retrieve the date value from your database.
I do not know if there is a wordpress limitation but you can trigger a Ajax-Request which reads out the database value and give you as a response the date string as a JavaScript variable.
This variable can also be passed to the createDate(date) function. With these two date objects you can call easily compare the date with the time in milliseconds -> getTime() function of date object.
Regards

JQuery and PHP Date difference

I am using a jquery date picker and also setting a date through php date('Y-m-D') functions. Both of them give different date for today. Jquery picker fills the field with the date that is one day ahead of php date(). Here is the function for jquery. I need jquery to show same date for today as php.
<script type="text/javascript" charset="utf-8">
var $j = jQuery.noConflict();
$j(function()
{
// initialise the "Select date" link
$j('#date-pick')
.datePicker(
// associate the link with a date picker
{
createButton:false,
startDate: '01/01/1970',
endDate: (new Date()).asString()
//endDate:<?php echo date('y-m-d'); ?>
}
).bind(
// when the link is clicked display the date picker
'click',
function()
{
updateSelects($j(this).dpGetSelected()[0]);
$j(this).dpDisplay();
return false;
}
).bind(
// when a date is selected update the SELECTs
'dateSelected',
function(e, selectedDate, $td, state)
{
updateSelects(selectedDate);
}
).bind(
'dpClosed',
function(e, selected)
{
updateSelects(selected[0]);
}
).val(new Date().asString()).trigger('change');
var updateSelects = function (selectedDate)
{
var selectedDate = new Date(selectedDate);
if(selectedDate != "Invalid Date")
{
$j('#d').val(selectedDate.getDate());
$j('#m').val(selectedDate.getMonth()+1);
$j('#y').val(selectedDate.getFullYear());
}
}
// listen for when the selects are changed and update the picker
// default the position of the selects to today
var today = new Date();
updateSelects(today.getTime());
});
</script>
jQuery uses the client computer's date while php uses the server's date. They're basically different if you haven't set the default timezone in php. Take a look at this:
http://php.net/manual/en/function.date-default-timezone-set.php
You can set the default timezone in php.ini file located on the PHP main directory (Eg. PHP5.4)
As for the using of the server's date in the datepicker:
A quick google search lead me to this: how to display server side dates in jquery datepicker?
basically what they have done is creating a new date based on the current timestamp:
$timestamp = strtotime("2012-08-02");
minDate: new Date('<?php echo $timestamp; ?>');
DO NOT TRUST THE CLIENTS DATE AND TIME
These values can be altered at a whim.
Just use them on advisement.
Besides Javascript is there to enhance the users experience (i.e. make it more interactive). But at the end of the day you will have to pick up the pieces it you do not validate and verify the data you get from the client

Categories