Is it possible to get the current format applied to bootstrap datepicker from the bootstrap-datepicker object?
I have several datepickers with different formats and I'd like to get the format in each of them to apply different validation methods based on the current format.
I have 3 solutions for you.
Solution 1: Declare dateFormat variable and use it on datepicker init or anywhere you want.
var dateFormat = 'mm/dd/yyyy';
$('.datepicker').datepicker({
format: dateFormat ,
startDate: '-3d'
});
Solution 2: Declare dateFormat variable and use it on $.fn.datepicker.defaults to apply for all datepickers and use it anywhere you want.
var dateFormat = 'mm/dd/yyyy';
$.fn.datepicker.defaults.format = dateFormat;
$('.datepicker').datepicker({
startDate: '-3d'
});
Solution 3: Init datepicker by data-date-format in HTML and you can get it by $("#datepicker").attr('data-date-format').
console.log($("#datepicker").attr('data-date-format'));
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input id="datepicker" class="datepicker" data-date-format="mm/dd/yyyy">
Related
I have already initialized my jquery datepicker with the format dd-M-yyyy. On some particular event I want to set that datepicket with today's date with the respective date format(dd-M-yyyy) that already I have set. I tried these codes but none of them are working, help me..
html
<input id="SD_WO_DATE" readonly="readonly" type="text">
js
$("#SD_WO_DATE").datepicker().datepicker( "option", "defaultDate", new Date() );
and
$("#SD_WO_DATE").datepicker().datepicker("setDate", new Date());
These are setting date with mm-dd-yyyy which I don't want.
Demo
Use setDate property of datepicker with today as the value,
$('#SD_WO_DATE').datepicker({ dateFormat: 'dd-M-yy' });
$('button').click(function(){
$('#SD_WO_DATE').datepicker('setDate', 'today');
});
I'm trying to find a date of birth date picker similar to the one next to the bottom on this page: http://www.pradosoft.com/demos/quickstart/?page=Controls.Samples.TDatePicker.Home
Have you seen such date picker in jQuery ?.
I actually use a combination of the day selector with dropdowns from the jQuery UI datepicker for birthday selection like so:
$('.datepicker').datepicker({
changeYear:true,
changeMonth:true,
showMonthAfterYear:true,
yearRange:'1920:' + $.datepicker.formatDate('yy', new Date())
});
I am able to bring the jquery calendar with the following code.
$( "#startDate, #endDate" ).datetimepicker();
this also brings me date picker and time I get the following format : 10/08/2013 05:23 PM but I want the selected date to have the following format 2013-05-30 19:02:51.497 how do I do that with jquery?
thanks
You can check it by using jquery-ui-datetimepicker-plugin
$('#startDate, #endDate')
.datetimepicker({ dateFormat: 'yy-mm-dd', timeFormat: 'hh:mm:ss' });
I have followed this
but did not work and working one is
$("#startDate, #endDate").datetimepicker({ dateFormat: 'dd-mm-yy hh:mm:ss'});
How to set date for an inline Datepicker in jqueryUI?
When initializing a datepicker, you'd use the defaultDate option:
$("#date").datepicker({
defaultDate: '01/26/2014'
});
FIDDLE
when changing the date later, you'd use setDate method:
$("#date").datepicker();
// more code
$("#date").datepicker('setDate', '01/26/2014');
FIDDLE
You can set multiple dates as well by using this:
allBookings = []
_.each(Session.get('thisGuide').bookings,function(e){
allBookings.push(moment(e).format('MM/DD/YYYY'))
})
$('#datepicker').datepicker('setDates',allBookings)
I want to use simple JQuery datapicker but not only to select the date. I want to add hours to the date format but I also want to preserver the classic vie of the calendar. I just want to add hours as extra functionality to define precisely the time. Is this possible?
<script type="text/javascript">
//For calendar
$(".datepicker").datepicker({
inline: true,
showWeek: true,
firstDay: 1,
dateFormat: 'yyyy-mm-dd HH:MM:ss',
});
</script>
http://trentrichardson.com/examples/timepicker/
you can try the above plugin with the combination of datepicker
you can even use the default $('.datepicker').datetimepicker();
jQuery UI's datepicker picks dates, not times. You can add a distinct field for the hours, e.g. a select field.