Get php variable containing date from jquery datepicker - javascript

I have a jquery datepicker defined like this :
HTML/php:
<input id="datepicker" name="date" placeholder="Date" />
Javascript:
<script>
$(document).ready(function() {
$("#datepicker").datepicker();
});
</script>
This works perfectly but i need to get the date in a php variable. I tried $_POST["date"] but this does not work. Could you help me ? Thanks !

The problem is solved, I don't really know where the problem came from. I still use $_POST["date"] to get the date, then I convert it from dd/mm/yyyy to yyyy-mm-dd (because my sql request requires this format) and it works..
Anyway, thanks everyone !

Related

jQuery data('datepicker').getDate() return Invalid date

I have this input that I am using for dates.
<input id="txtsdate" class="form-control" type="text">
<script>
$('#txtsdate').data('datepicker').setStartDate(new Date(TimezoneDate()));
$('#txtsdate').data('datepicker').setEndDate(Infinity);
$('#txtsdate').data('datepicker').setDate(sFulllDate);
</script>
until this point my code works well and i set normally the date. But when i try to get the date from the input and i am using
var sDate = $('#txtsdate').data('datepicker').getDate();
am getting 'Invalid Date'.
I have read this article https://github.com/uxsolutions/bootstrap-datepicker/issues/923
but doesn't seems to help me.
Try This Simply code to get input value of any text box using jquery
var sDate = $("#txtsdate").val();

javascript - get the date value

I have a problem. I use a date picker in my html page which I want to get value of input date using jquery. I used this :
var birthday_date = $("#birthday_date").val();
but it's not working. I checked the inspect code then realise when I used date picker, the input tag (which used for date) becomes to this :
<input id="textbox1"
name="birthday_date"
data-targetselector="#textbox1"
class="form-control"
data-mddatetimepicker="true"
placeholder="year/month/day"
data-placement="top"
maxlength="10"
data-mdpdatetimepicker=""
data-trigger="click"
data-enabletimepicker="false"
data-mdformat="yyyy/MM/dd"
data-mdpdatetimepickerselecteddatetime="
{"Year":2011,"Month":8,"Day":2,"Hour":9,"Minute":13,"Second":14}"
data-original-title=""
title=""
data-mdpdatetimepickershowing="true"
aria-describedby="popover30621"
type="text">
the value of the date is this part:
mdpdatetimepickerselecteddatetime="{"Year":2011,"Month":8,"Day":2,"Hour":9,"Minute":13,"Second":14}"
the time is not matter, I just wanna date , google gave me nothing and I have no idea how can I get the value like this, any help? or something to help me?
If you are using datepicker, you can access the value like this:
var date = $('#textbox1').datepicker('getDate');

How to give a date format as dd-mm-yyyy in IE as like I am getting in google chrome

As input type=date won't works in IE is there any possible way to get dd-mm-yyyy format same like as we are getting in other browsers? Please help me out.
Well, I tested below code in IE/Chrome/Firefox and its working fine.
<script src="//cdn.jsdelivr.net/webshim/1.14.5/polyfiller.js"></script>
<script>
webshims.setOptions('forms-ext', {types: 'date'});
webshims.polyfill('forms forms-ext');
</script>
<input type="date" />
Hope this will help you :)

Select date range in one calendar

I really like plugin daterangepicker, but it uses 2 calendars for selecting a date range.
Is it possible to select a date range with only 1 calendar? do you know other plugins?
I want to make something like that
You can refer the below link. It might help you.
http://www.daterangepicker.com/
<input type="text" name="daterange" value="01/01/2015 - 01/31/2015" />
<script type="text/javascript">
$(function() {
$('input[name="daterange"]').daterangepicker();
});
</script>
You can use the singleDatePicker on the calendar configuration, and set it true.
singleDatePicker: true,
http://www.daterangepicker.com/#example3

bootstrap 3 datepicker (eonasdan version) provides a datetime object with getDate(). not a string

I am using the following bootstrap 3 datepicker.
http://eonasdan.github.io/bootstrap-datetimepicker/
it works fine but there is an issue . during the change event
the output thrown out is a js object. i want a string. is taht possible.
there is another question asked along the same lines. but current version of datepicker has been updated and the old code does not run in jsfiddle.
html code is as follows:
<div class="form-group">
<div class='input-group date' id='datetimepicker5' data-date-format="YYYY/MM/DD">
<input type='text' class="form-control" />
<span class="input-group-addon"><span class="glyphicon glyphicon-time"></span>
</span>
</div>
</div>
my jquery code is as follows ;
$(function () {
$('#datetimepicker5').datetimepicker({
pickTime: false,
useCurrent: true,
showToday: true,
language : 'en'
});
$('#datetimepicker5').data('DateTimePicker').show();
});
//.... on change event
$('#datetimepicker5').on('dp.change', function() {
var t3= $('#datetimepicker5').data("DateTimePicker").getDate();
alert (t3.format('YYYY-MM-DD)); // this is the new change and works perfect
});
any help is really appreciated
If I interpret the installation instruction correctly, Eonasdan already has moment.js as a dependency. This answer from a related question provides some sample code on using moment.js to format a date in JavaScript.
If for some reason moment.js is not available, you can fall back to the native JavaScript functions. See this answer from the same question as I previously referred to.

Categories

Resources