How to set default time in bootstrap datetime picker - ruby-on-rails

I am using bootstrap datetime picker to display calender, when I select the date in the calender I want to set my time to to 00:00 hours:minutes on the selected date.
this is my script
<script>
$(function() {
`enter code here`$('#datetimepicker1').datetimepicker({
language: 'en',
setTime: '00:00 AM'
});
});
</script>
please let me know how to set default time.

you can set format like this:
$('#datetimepicker1').datetimepicker({
language: 'en',
pickTime: false,
format: "dd/MM/yyyy 00:00:00"
});

Related

Datetimepicker - How to set stored database date instead of today date

I am using 'bootstrap3-datetimepicker-rails' gem and I would like set my stored date in the input datetimepicker instead of today date.
This is my code:
$(document).on('dp.change','input.gas_ref_date', function(e){
$('input#datetimepicker_gas_ref_date').datetimepicker({maxDate: moment(), format:'DD-MM-YYYY' });
});
});
But always the datetimepicker shows a today date.
I have tried this other solution, but does not works:
$(document).on('dp.change','input.gas_ref_date', function(e){
var my_stored_date = this.value;
$('input#datetimepicker_gas_ref_date').datetimepicker({maxDate: moment(), format:'DD-MM-YYYY', defaultDate: new Date(my_stored_date) });
});
});

How to display only date in KendoDateTime picker

I've placed a kendo DateTime Picker on a web page.
According to the requirement initially it should display only date and if user needs then he/she can select the time as well.
Below is the code which initially fill the kendo datetime picker:
<input id="txtDate" type="text" maxlength="10" style="width: 250px;" value="" />
<script type="text/javascript">
$('#txtDate').kendoDateTimePicker({ value: new Date() });
</script>
The above code fill date and time. But i want to fill only current date.
I tried with the following code to check if it can fill only date. But it adds the 12:00 AM with date.
$('#txtDate').kendoDateTimePicker({ value: new Date('04/30/2017') });
Is there any way to fill only date in Kendo DateTime picker?
What you are looking is kendoDatePicker, which will allows user to select only date.
$(document).ready(function()
$("#txtDate").kendoDatePicker();
});
Edit: or add formatting property to kendoDateTimePicker, which will effect how value is displayed for user.
$('#txtDate').kendoDateTimePicker({
value: new Date(),
format: 'MM/dd/yyyy'
});
If you never need to display the time one possible option might be to store the datetime value as an attribute of the current widget and on the submit event of the form manually ovverride the values:
<script>
$(document).ready(function () {
$("#datetimepicker").kendoDateTimePicker({
format: "yyyy/MM/dd",
change: function(data){
data.sender.element.attr("value", data.sender.value());
}
});
});
$("form").on("submit", function(){
$("input").each(function(){
var inputValue = $(this).attr("value");
if(inputValue){
$(this).val(inputValue);
}
});
})
</script>
If you want to display the time after the user pick a time you can change the format of the widget subscribing a function to the open event:
<input id="datetimepicker" />
<script>
$("#datetimepicker").kendoDateTimePicker({
format: "yyyy/MM/dd",
value: new Date(),
open: function(e){
if(e.view == "time"){
this.setOptions({format: "yyyy/MM/dd HH:mm"})
}
if(e.view == "date"){
this.setOptions({format: "yyyy/MM/dd"})
}
}
});
You can build on the answers given above and detect when a time is selected then reapply a display format in javascript.
Via jQuery:
$('#txtDate').datetimepicker({
format: 'L'
});
Instead of using Kendo.DateTimePickerFor you can use DatePickerFor.
This way you can get rid of hour part.
#(Html.Kendo().DatePickerFor(model => model.StartDate).HtmlAttributes(new { #class = "form-control" , required="required"}))

How to set up 24 hour format in MobiScroll?

I am using latest version of MobiScroll datetime plugin and i need to display date in 24h format without AM/PM, so i doing it like
$('#datetime-start, #datetime-end').mobiscroll().datetime({
minDate: new Date(now.getFullYear(), now.getMonth(), now.getDate()),
display: 'modal',
animate: 'pop',
mode: 'mixed',
// 2013-03-15 11:26:17
dateFormat: 'yy-mm-dd',
timeFormat: 'HH:ii:ss',
timeWheels: 'hhii'
});
but there still 12h format... Is there any way to set up 24 format?
Your timeWheels attribute is incoreect, change it to this:
$('#datetime-start, #datetime-end').mobiscroll().datetime({
minDate: new Date(now.getFullYear(), now.getMonth(), now.getDate()),
display: 'modal',
animate: 'pop',
mode: 'mixed',
// 2013-03-15 11:26:17
dateFormat: 'yy-mm-dd',
timeFormat: 'HH:ii:ss',
timeWheels: 'HHii'
});
So change this:
timeWheels: 'hhii'
to this:
timeWheels: 'HHii'

How to combine jquery date-picker and jquery full calendar

Can any one tell me how I could update a selection in a date picker to a full calendar ie When user selects date from DatePicker then FullCalendar loads events for given date.
Take a look at this : Issue 167: Mini Calender to control Main Calender.
Or make the combination with following example :
$(document).ready(function() {
$("#fullcalendar").fullCalendar({
// .....
});
$('#datepicker').datepicker({
inline: true,
onSelect: function(dateText, inst) {
var d = new Date(dateText);
$('#fullcalendar').fullCalendar('gotoDate', d);
}
});
}
<div id="fullcalendar"></div>
<div id="datepicker"></div>
The "gotoDate (method)" would help you select a date programatically in fullcalendar. So let the user select a date using jquery date picker and register a onchange event on the text input that captures the date. When the onchange fires, use gotoDate to set the date in fullcalendar. Refer - http://arshaw.com/fullcalendar/docs/current_date
This might help anyone coming to this answer to add a gotoDate datepicker to fullcalendar as a custom button
customButtons: {
gotoDate: {
text: 'Go to date',
click: function () {
$(this).datepicker({
autoclose: true
});
$(this).datepicker().on('changeDate', function (e) {
$('#fullcalendar').fullCalendar('gotoDate', e.date);
});
$(this).datepicker('show');
}
},
},
footer: {
'center': 'gotoDate'
},

how to set the minimum date for JQuery datepicker retrieved from model

$('#bid_work_end_date').datepicker(
{
dateFormat: 'dd-mm-yy',
minDate: -0
});
In this code, i have set the min date as today's date but i want to set it by retrieving from a rails model. I cannot find out a way to do it??
try this
var oDate=new Date();
var day=oDate.getDate();
var month=oDate.getMonth()+1;
var year=oDate.getFullYear();
var new_date=day+"-"+month+"-"+year;
$('#bid_work_end_date').datepicker( { dateFormat: 'dd-mm-yy', minDate: new_date });

Resources