0
$(function() {
    $('#defaultInline').datepick({

       dateFormat: 'yyyy-mm-dd',
       onSelect: showDate


    });
    function showDate(date) {
       var dates2 = $('#defaultInline').datepick('getDate');  // this works 
       var dates3 =  $.datepick.formatDate('yyyy-mm-dd',dates2) /// this give an error 
    alert('The date chosen is ' + dates2);
    }

});

Alert (dates2) works but dates 3 gives an error.....any ideas ? basically i want to just get the date from an inline calender in a particular format....right now it shows up as Tue Oct 30 2012 12:00:00 GMT+0530 (India Standard Time) but all i want is 2012-10-30 ....

the error i get is : TypeError: g.getFullYear is not a function

Apurva
  • 461
  • 1
  • 5
  • 19

2 Answers2

1
$(function() {
    $('#defaultInline').datepick({

       dateFormat: 'yyyy-mm-dd',
       altField: '#scb_date', // this is what i added 
      onSelect: showDate

    });
    function showDate() {
          var date2=$("#scb_date").val();
          alert(date2);
    }

});

scb is a hidden input field...and the value can be read from that... now i know there are better ways to do what i am doing.. but this was the easiest that i found...if you have something better please let me know...

Apurva
  • 461
  • 1
  • 5
  • 19
  • thx for that altField: '#id' writes the given dateFormat: in this field (in my case hidden input) now i can post it via form or get its val to do further stuff! :) – ggzone Nov 28 '13 at 16:01
0

This should work:

var date = $('#datepicker').datepicker({ dateFormat: 'dd-mm-yy' }).val();

For more information jQuery UI DatePicker - Change Date Format

Community
  • 1
  • 1
gotqn
  • 42,737
  • 46
  • 157
  • 243
  • okay this is jquery ui datepicker and what i was using is jquery datepicker by keith woood...the above problem was solved ... see below... – Apurva Oct 30 '12 at 07:49