111

I am using bootstrap date time picker in my web application, made in PHP/HTML5 and JavaScript. I am currently using one from here: http://tarruda.github.io/bootstrap-datetimepicker/

When I am using the control without time, it doesn't work. It just shows a blank text box.

I just want to remove time from date time picker. Is there any solution for this?

<div class="well">
    <div id="datetimepicker4" class="input-append"> 
        <input data-format="yyyy-MM-dd" type="text"></input> 
        <span class="add-on"> 
            <i data-time-icon="icon-time" data-date-icon="icon-calendar"> </i> 
        </span> 
    </div> 
</div> 
<script type="text/javascript"> 
    $(function() { 
        $('#datetimepicker4').datetimepicker({ pickTime: false }); 
    }); 
</script>
Celt
  • 2,469
  • 2
  • 26
  • 43
Chirag Sudra
  • 1,219
  • 2
  • 8
  • 8

21 Answers21

147

Check the below snippet

<div class="container">
<div class="row">
    <div class='col-sm-6'>
        <div class="form-group">
            <div class='input-group date' id='datetimepicker4'>
                <input type='text' class="form-control" />
                <span class="input-group-addon"><span class="glyphicon glyphicon-time"></span>
                </span>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        $(function() {              
           // Bootstrap DateTimePicker v4
           $('#datetimepicker4').datetimepicker({
                 format: 'DD/MM/YYYY'
           });
        });      
    </script>
</div>

You can refer http://eonasdan.github.io/bootstrap-datetimepicker/ for documentation and other functions in detail. This should work.

Update to support i18n

Use localized formats of moment.js:

  • L for date only
  • LT for time only
  • L LT for date and time

See other localized formats in the moment.js documentation (https://momentjs.com/docs/#/displaying/format/)

Ck Maurya
  • 2,225
  • 2
  • 17
  • 26
  • The pickDate option you cite is not documented in the documentation you link to. – Jeremy Burton Jan 27 '15 at 01:01
  • 2
    The answer is wrong regarding the question. The question was how to disable the time, not the date. Besides, that code probably still won't work, since it attachs the datepicker to the parent `div` (maybe the library handles this and searches for ``-sub-elements) – Peter Ilfrich Jan 29 '15 at 00:45
  • 12
    pickDate and pickTime have been removed in the current version of Eonasdan's Bootstrap Datetimepicker. Use format instead. – gl03 Mar 11 '15 at 14:16
  • 3
    This is wrong, setting format breaks internationalisation – Kikin-Sama Jul 17 '17 at 23:44
44

I tried all of the solutions posted here but none of them worked for me. I managed to disable the time by using this line of code in my jQuery:

$('#datetimepicker4').datetimepicker({
    format: 'YYYY-MM-DD'
});

This set the format to date only and disabled the time completely. Hope this helps.

Celt
  • 2,469
  • 2
  • 26
  • 43
  • 5
    Of all the solutions on this page, this is the only one that worked for me. Using v4.7.14 of bootstrap-datetimepicker lib. – Josh Buchea Mar 31 '15 at 17:15
  • 2
    Just to avoid any confusion since there seems to be a few similarly named datetime pickers, I'll point out that this worked for me for this particular plugin: http://eonasdan.github.io/bootstrap-datetimepicker/ – Paul Calabro Jun 05 '15 at 11:10
  • Thanks, this worked for me, however, my form still shows the icon to switch to the time-picker, and it allows you switch, then shows 00:00. It doesn't change what is submitted with the form, but is there any way to remove the clock icon so that the user cannot access the time picker part of the form? Thanks again! – jackerman09 Jun 22 '15 at 02:50
  • You must be using a different version of the DateTimePicker because the time icon disappeared on mine. – Celt Jun 23 '15 at 14:46
27

This is for: Eonasdan's Bootstrap Datetimepicker

First of all I would provide an id attribute for the <input> and then initialize the datetimepicker directly for that <input> (and not for the parent container):

<div class="container">
  <input data-format="yyyy-MM-dd" type="text" id="datetimepicker"/>
</div>
<script type="text/javascript">
  $(function() {
    // Bootstrap DateTimePicker v3
    $('#datetimepicker').datetimepicker({
      pickTime: false
    });
    // Bootstrap DateTimePicker v4
    $('#datetimepicker').datetimepicker({
      format: 'DD/MM/YYYY'
    });
  });
</script>

For v3: Contrary to Ck Maurya's answer:

  • pickDate: false will disable the date and only allow to pick a time
  • pickTime: false will disable the time and only allow to pick a date (which is what you want).

For v4: Bootstrap Datetimepicker now uses the format to determine if a time-component is present. If no time component is present, it won't let you choose a time (and hide the clock icon).

Community
  • 1
  • 1
Peter Ilfrich
  • 3,727
  • 3
  • 31
  • 35
  • Why was this voted down? This is the only answer that correctly explains that the plugin's option have changed in the latest version. Would have saved me a few minutes of confusion if this was the top answer. – gl03 Mar 11 '15 at 14:14
  • 1
    It has to be CAPITALS date for it to work, strangely – sidonaldson Mar 16 '15 at 14:56
  • Yeah, that's just the way how the date format is specified in Javascript (contrary to the way date/time format is defined in Java). Took me some time to figure that out as well. – Peter Ilfrich Mar 17 '15 at 15:22
  • Thanks, this worked for me, however, my form still shows the icon to switch to the time-picker, and it allows you switch, then shows 00:00. It doesn't change what is submitted with the form, but is there any way to remove the clock icon so that the user cannot access the time picker part of the form? Thanks again! – jackerman09 Jun 22 '15 at 03:45
  • jackerman09, please be aware of the version of datetimepicker you use. The behaviour described applies to Eonasdan's datetimepicker v3, v4. If you are using the latest (which you should), then not having a time component in the format will automatically remove the clock icon. And please don't post the same comment to multiple answers... It suggests a lack of motivation... – Peter Ilfrich Jun 22 '15 at 04:24
23
$('#datetimepicker').datetimepicker({ 
    minView: 2, 
    pickTime: false, 
    language: 'pt-BR' 
});

Please try if it works for you as well

ImBhavin95
  • 1,494
  • 2
  • 16
  • 29
19

I spent some time trying to figure this out due to the update with DateTimePicker. You would enter in a format based off of moment.js documentation. You can use what other answers showed:

$('#datetimepicker').datetimepicker({ format: 'DD/MM/YYYY' });

Or you can use some of the localized formats moment.js provides to do just a date, such as:

$('#datetimepicker').datetimepicker({locale: 'fr', format: 'L' });

Using this, you are able to display only a time (LT) or date (L) based on locale. The documentation for datetimepicker wasn't clear to me that it automatically adapts to the input provided (date or only time) via moment.js format. Hope this helps for those still looking.

Janusz Skonieczny
  • 17,642
  • 11
  • 55
  • 63
ishmael62
  • 291
  • 2
  • 5
  • 4
    This is the best answer, because it includes the locale-dependent format, instead of "hardcoding" the format. – Nahn Dec 18 '15 at 17:58
7
<div class="container">
  <input type="text" id="datetimepicker"/>
</div>

<script type="text/javascript">
  $(function() {
    // trigger datepicker
    $('#datetimepicker').datetimepicker({
       pickTime: false,
        minView: 2,
        format: 'dd/mm/yyyy',
        autoclose: true,
    });
  });
</script>
wolver
  • 197
  • 3
  • 16
5

Initialize your datetimepicker like this

For disable time

$(document).ready(function(){
    $('#dp3').datetimepicker({
      pickTime: false
    });
});

For disable date

$(document).ready(function(){
    $('#dp3').datetimepicker({
      pickDate: false
    });
});

To disable both date and time

$(document).ready(function(){
   $("#dp3").datetimepicker('disable'); 
});

please refer following documentation if you have any doubt

http://eonasdan.github.io/bootstrap-datetimepicker/#options

muni
  • 1,362
  • 2
  • 19
  • 21
5

This shows only date:

$('#myDateTimePicker').datetimepicker({
        format: 'dd.mm.yyyy',
        minView: 2,
        maxView: 4,
        autoclose: true
      });

More on the subject here

FrenkyB
  • 6,625
  • 14
  • 67
  • 114
3

For bootstrap 4 version this code working;

$('#payment-date-time-select').datetimepicker({
    startView:2,
    minView:2,
});
Ethem
  • 81
  • 1
  • 5
3

In my case, the option I used was:

var from = $("input.datepicker").datetimepicker({
  format:'Y-m-d',
  timepicker:false # <- HERE
});

I'm using this plugin https://xdsoft.net/jqplugins/datetimepicker/

aldrien.h
  • 3,437
  • 2
  • 30
  • 52
2
    $(function () {
        $('#datetimepicker9').datetimepicker({
            viewMode: 'years',
            format: 'DD/MM/YYYY' /*Add this line to remove time format*/
        });
    });
Paul
  • 107
  • 1
  • 11
1
your same code work's fine, just add some link reference

<!DOCTYPE HTML>
<html>
    <head>
        <link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/css/bootstrap-combined.min.css" rel="stylesheet">
        <link rel="stylesheet" type="text/css" media="screen"
              href="http://tarruda.github.com/bootstrap-datetimepicker/assets/css/bootstrap-datetimepicker.min.css">


    </head>
    <body>
        <div class="well">
            <div id="datetimepicker4" class="input-append"> 
                <input data-format="yyyy-MM-dd" type="text"></input> 
                <span class="add-on"> 
                    <i data-time-icon="icon-time" data-date-icon="icon-calendar"> </i> 
                </span> 
            </div> 
        </div> 

        <script type="text/javascript"
                src="http://cdnjs.cloudflare.com/ajax/libs/jquery/1.8.3/jquery.min.js">
        </script> 
        <script type="text/javascript"
                src="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/js/bootstrap.min.js">
        </script>
        <script type="text/javascript"
                src="http://tarruda.github.com/bootstrap-datetimepicker/assets/js/bootstrap-datetimepicker.min.js">
        </script>
        <script type="text/javascript"
                src="http://tarruda.github.com/bootstrap-datetimepicker/assets/js/bootstrap-datetimepicker.pt-BR.js">
        </script>
        <script type="text/javascript">
            $(function () {
                $('#datetimepicker4').datetimepicker({pickTime: false});
            });
        </script>

    </body>
    </html>
Hrushi
  • 309
  • 3
  • 6
1

The selector criteria is now an attribute the DIV tag.

examples are ...

data-date-format="dd MM yyyy" 
data-date-format="dd MM yyyy - HH:ii p
data-date-format="hh:ii"

so the bootstrap example for dd mm yyyy is:-

<div class="input-group date form_date col-md-5" data-date="" 
    data-date-format="dd MM yyyy" data-link-field="dtp_input2" data-link-format="yyyy-mm-dd">
..... etc ....
</div>

my Javascript settings are as follows:-

            var picker_settings = {
                language:  'en',
                weekStart: 1,
                todayBtn:  1,
                autoclose: 1,
                todayHighlight: 1,
                startView: 2,
                minView: 2,
                forceParse: 0
            };

        $(datePickerId).datetimepicker(picker_settings);

You can see working examples of these if you download the bootstrap-datetimepicker-master file. There are sample folders each with an index.html.

Ato Thejay
  • 17
  • 2
0

I know this is late, but the answer is simply removing "time" from the word, datetimepicker to change it to datepicker. You can format it with dateFormat.

      jQuery( "#datetimepicker4" ).datepicker({
        dateFormat: "MM dd, yy",
      });
Dawn Green
  • 483
  • 4
  • 16
  • I'm not sure why you dinged my comment, Dmitry, because it in fact answers the poster's question. The fact that there are various dateFormats is not relevant to the question and is only shown here as an example. – Dawn Green Sep 02 '15 at 18:32
0

Disable time in boostrap datetime picker...

   $(document).ready(function () {
        $('.timepicker').datetimepicker({
            format: "dd-mm-yy",
        });
    });

Disable date in boostrap datetime picker...

   $(document).ready(function () {
        $('.timepicker').datetimepicker({
            format: "HH:mm A",
        });
    });
Gilsha
  • 14,431
  • 3
  • 32
  • 47
0
<script type="text/javascript">
        $(function () {
                  $('#datepicker').datetimepicker({
                     format: 'YYYY/MM/DD'
               });
            });
</script>
Viral M
  • 261
  • 2
  • 14
0

This allows to show time in input field but hides time picker button, which is second li element in accordion

.bootstrap-datetimepicker-widget .list-unstyled li:nth-child(2){
    display: none;
}
0

I am late to this post, but I want to share my experience. Some people suggest the code below to turn off the time picker and it did fix the issue.

$('#datetimepicker').datetimepicker({ 
    minView: 2, 
    pickTime: false
});

The reason behind I think they are using this library https://www.malot.fr/bootstrap-datetimepicker/ instead of this library http://eonasdan.github.io/bootstrap-datetimepicker/

ikhvjs
  • 5,316
  • 2
  • 13
  • 36
-1

Here's the solution for you. It's very easy to just add code like this:

    $('#datetimepicker4').datetimepicker({ 

    pickTime: false 

    minview:2;(Please see here.)

    }); 
Donny
  • 94
  • 6
-3

Not as put off time and language at a time I put this and not work

$(function () {
    $('#datetimepicker2').datetimepicker({
              locale: 'es',
              pickTime: false
          });
});
Mosh Feu
  • 28,354
  • 16
  • 88
  • 135
-3
 $("#datetimepicker4").datepicker({
    dateFormat: 'mm/dd/yy',
    changeMonth: true,
    changeYear: true,
    showOtherMonths: true,
    selectOtherMonths: true,
    pickTime: false,
    format: 'YYYY-MM-DD'
});