Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show only date in JQuery Datetimepicker addon?

I've searched high and low for an answer to my question but haven't found one, I did find two related questions though: JQuery Datepicker should display date only , jQuery UI DateTimepicker - cannot hide the time

But they didn't solve my problem.

I'm using Trent Richardsons datetimepicker and I would like it to show only date in the textbox. The answer to why I'm not using the datepicker without the addon is because sometimes I want it to show datetime and sometimes only date.

I've can hide the timepicker with the following code:

    datetimepicker("option", "showTimepicker", false);

The time disappears from my textbox but the date has a trailing space, "2013-11-01 " I've tried the option for separator but no luck.

    datetimepicker("option", "separator", "");

Anyone got an idea how I can solve this?

A bit clarification, I'm trying to write kind of a component that can be used through a large solution where it sometimes needs to be a datetimepicker and sometimes a datepicker. This "component" contains an input (my datetimepicker) that is wrapped in some html. It also has properties that can be set, one of them is the SetDateOnly(), and that is where I'm trying to get the datepicker to show only date.

like image 860
Robert Persson Avatar asked Nov 11 '13 15:11

Robert Persson


People also ask

What is DateTimePicker in jQuery?

A date-picker of jQuery UI is used to provide a calendar to the user to select the date from a Calendar. This date picker usually connected to a text-box so user selection of date from the calendar can be transferred to the textbox.


2 Answers

Try this options:

$("#selector").datetimepicker({
  minView: 2,
  format: 'YYYY-MM-DD'
});
like image 95
Ibanêz Avatar answered Sep 19 '22 23:09

Ibanêz


Then you can go with showTimePicker like this:-

On Form Load

$(document).ready(function(){
    $('#selector').datetimepicker({
        'showTimepicker': false
    });     
});

On run time

$(".btn").click(function(){ 
    $('#selector').datetimepicker("destroy"); //destroys the previous settings.
    $('#selector').datetimepicker({
        'showTimepicker': false
    });                     
});
like image 34
GDG Avatar answered Sep 22 '22 23:09

GDG