Clear the value in a datetimepicker field

I'm sure this is simple and it's my understanding of jquery/javascript that is holding me back - but I can't get this to work.

All I need to do - is - When a button on the screen is clicked, clear some of the input field on the form back to their original values.

This is working fine, for all fields except a datetimepicker field.

Here is the relevant bits of code, that defines the input field :

<div class='form-group' id='START_DATEFormGroup'>    
<label for='START_DATE' class='col-sm-2 control-label' data-toggle='tooltip' data-placement='top' title=''>Start Date</label>
<div class='col-sm-8'>
<div class='input-group date form_date col-sm-3'  data-date-format='dd M yyyy' data-link-field='START_DATE' data-link-format='yyyy-mm-dd'>
<input class='form-control' size='16' type='text'  />
<input type='hidden' id='START_DATE' name='START_DATE' />
<span class='input-group-addon'>
<span class='glyphicon glyphicon-calendar'>
</span> // group-addon
</span> // calendar
</div> // form_date
</div> // col-sm-8
</div> // form-group

I am initializing datetimepicker as follows :

function enableDatepicker(){
    $( document ).ready(function() { 
            format: 'dd M yyyy',
            minView: 2,
            autoclose: 1,

To clear the input fields down I have :

function clearActionForm(){
     // code here to clear the various input fields to null or their initial values.
     // Need statements to clear the datetimepicker field to null.


So, can someone give me the line(s) of code I need to insert into clearActionForm() in order to clear the START_DATE field to null.




use this line $('.form_date').data("DateTimePicker").clear()



If you are using the eonasdan datetimepicker use the following:

// clears

// updates with date
$("#form_date").data("DateTimePicker").date(new Date());

// or update with string
var myCoolDate = "27 05 1975";

// or update with a moment
 var moment = moment().add(2, 'd');

Below is a demo of using different types of changes.

$(function() {
    format: 'dd M YYYY',

$('#clear').click(function() {

$('#date').click(function() {
  var sysdate = new Date();
  $("#datetimepicker1").data("DateTimePicker").date(new Date());

$('#string').click(function() {
  var myCoolDate = "27 05 1975";

$('#moment').click(function() {
  var now = moment().add(2, 'd');
<link href="" rel="stylesheet" />
<link href="" rel="stylesheet" />

<script src=""></script>
<script src=""></script>
<script src=""></script>
<script src=""></script>

<div class="container">
  <div class="row">
    <div class='col-sm-6'>
      <div class="form-group">
        <div class='input-group date' id='datetimepicker1'>
          <input type='text' class="form-control" />
          <span class="input-group-addon">
                        <span class="glyphicon glyphicon-calendar"></span>

<input type='button' id='clear' Value='Clear Date'>
<input type='button' id='date' Value='Set with date'>
<input type='button' id='string' Value='Set with string'>
<input type='button' id='moment' Value='Set with moment'>


Assuming that you are using the datetimepicker plugin from, one quick way to clear the datetimepicker's current value would be the following:


As an alternative (this sets the value of the datetimepicker to the current time):

  value: (new Date()).toLocaleString()

This value does not not match the format of the datetimepicker, but will be converted to the correct format automatically when the datetimepicker is used.


If you are using the eonasdan datetimepicker use the following:

// clears

// updates to now
$j(".form_date").data("DateTimePicker").setDate(new Date());

// or update to a given date
var myCoolDate = "05/27/1975";

Easy way to rest the selected date as well as highlighted date by below concept

$('#txtWQApprovalDate').datepicker('setDate', null).datepicker('fill');


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.