March 16, 2012

Jquery datepicker date format

Question by Dale

How do I get my date to display like this: “yy-mm-dd” inside my date input textbox after I have selected a date?

Information is reading from a database.
So I need it saved in a database again.

JavaScript:

<script>
  $(document).ready(function() {
  $("#from").datepicker();
});
</script>

Html code:

<div class="field">
        <label>Date</label>
       <input type="text" name="date" value="<?php value('date'); ?>" id="from" />   
        <?php if(isset($errors['date'])) { ?>
        <div class="error"><?php echo $errors['date']; ?></div>
        <?php } ?>
 </div>

Things that I have tried:

http://docs.jquery.com/UI/Datepicker#option-dateFormat

http://docs.jquery.com/UI/Datepicker/formatDate

jQuery UI DatePicker – Date Format

jquery ui datepicker date format

Answer by Starx

Define the format during initialization

$("#from").datepicker({
    dateFormat: 'yy-mm-dd'
});

The value is updated as well. See an example.

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!