bootstrap-datetimepicker show date only

19,491

Solution 1

Use date picker

$("#calender").datepicker({
    format: "mm/dd/yyyy"
});

Solution 2

To show date only use

format: 'L'

To show Time only use

format: 'LT'

Reference

https://github.com/Eonasdan/bootstrap-datetimepicker/issues/832
Share:
19,491
Junchao Gu
Author by

Junchao Gu

Updated on June 14, 2022

Comments

  • Junchao Gu
    Junchao Gu almost 2 years

    I am using this repo by smalot and I want to select and show date only (for some other places I am showing data and time, therefore selecting this repo). I can manage to use it for selecting date only but the generated date string is always yyyy-mm-dd hh:ii. And if I did not understand wrongly the format option is for parsing the initial date only but not setting dates.

    <div class="input-group date datetime dateonly" data-start-view="2" data-min-view="2" style="margin-bottom: 0;">
        <input class="form-control" size="16" type="text" placeholder="Release Date" id="release-date" name="release_date" value="{{ unit.release_dt|date:'Y-m-d' }}" style="cursor: default; background-color: #ffffff;">
        <span class="input-group-addon btn btn-primary"><span class="glyphicon glyphicon-th"></span></span>
    </div>
    

    I am setting startView and minView to be both 2 so that the user will need to select date only but I still got 2015-09-22 00:00 as the output-- I just want it to show 2015-09-22.

    In fact, by listening to changeDate and hide events, I can just set the value of date inputs. I am wondering if there is a less hacky and dirty way of doing it

    $('.datetimepicker').on('changeDate', function(e) {//get substring and set date input
    }).on('hide'....//same thing
    );
    
  • Junchao Gu
    Junchao Gu over 8 years
    I am not using this one... whether you are talking about eonasdan.github.io/bootstrap-datetimepicker or tarruda.github.io/bootstrap-datetimepicker
  • Parkash Kumar
    Parkash Kumar over 8 years
    Better to describe your answer.
  • Maddy
    Maddy over 8 years
    Sorry. My bad. I have edited my answer. Please do check.
  • Junchao Gu
    Junchao Gu over 8 years
    using data-format(in mark up) does not give me any request
  • Junchao Gu
    Junchao Gu over 8 years
    the key is data-date-format? I changed that but it is not working
  • Maddy
    Maddy over 8 years
    Yes, you are right. data-date-format is supposed to be set. Check the value of input having id as "release-date" you are getting after selecting date.