i am using jquery ui date picker for take fromDate and toDate
Following is the code of from date
<input name="from_date" id="from_date" maxlength="20" size="20" type="text"/>
$("#from_date").datepicker({
dateFormat: 'M dd, yy',
showButtonPanel: true,
changeMonth: true,
changeYear: true,
defaultDate: null
});
now i use the form to take the value in POST varible using PHP
If the fromDate field is blank then it take value '1970-01-01' i want it blank
i am using jquery ui date picker for take fromDate and toDate
Following is the code of from date
<input name="from_date" id="from_date" maxlength="20" size="20" type="text"/>
$("#from_date").datepicker({
dateFormat: 'M dd, yy',
showButtonPanel: true,
changeMonth: true,
changeYear: true,
defaultDate: null
});
now i use the form to take the value in POST varible using PHP
If the fromDate field is blank then it take value '1970-01-01' i want it blank
- 1 Can you include the PHP script where you get the variable ? are you casting to another type in PHP ? – Manse Commented Nov 2, 2011 at 10:29
-
Following is the my PHP code
$sdate = showDate($_POST['from_date'],'Y-m-d');
– Hardik Raval Commented Nov 2, 2011 at 10:32 - and the showDate() function ? – Manse Commented Nov 2, 2011 at 10:33
-
my guess is that when using
showDate
or otherdate
functions in PHP if the input isempty
ofnull
then the date that is created is epoch (ie 1970-01-01) – Manse Commented Nov 2, 2011 at 10:34 - 1 @Matteo - that wont work if the user can select that date .... – Manse Commented Nov 2, 2011 at 10:43
3 Answers
Reset to default 2Change your PHP function is use empty instead of null
function showDate($date,$format='m-d-y, h:i a') {
if(empty($date)) return ' ';
return date($format,strtotime($date));
}
try to set defaultDate: ''
or remove it at all
As you can find in jquery ui documentation (here), if you don't precise defaultDate
option, default date is current date.