views:

5023

answers:

4

Hi

I am using the UI DatePicker from jQuery UI as the stand alone picker.. i have this code

<div id="datepicker"></div>

And the follow JS

$('#datepicker').datepicker();

When i try to return the value with this code:

var date = $('#datepicker').datepicker('getDate');

I am returned this...

Tue Aug 25 2009 00:00:00 GMT+0100 (BST)

Which is totally the wrong format... Is there a way i can return DD-MM-YYYY ??

+8  A: 

Here's one specific for your code:

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

More general info available here:

AvatarKava
This doesn't seem to work.. where in my code do i put this?
tarnfeld
Sorry that was a bit generalized. I've updated with the actual block you'd want to use above.
AvatarKava
slight change... the above date var will give you an object. you prob want the date by calling val() on it. so: var date = $('#datepicker').datepicker({ dateFormat: 'dd-mm-yy' }).val();
Kevin Won
A: 

The format for parsed and displayed dates. This attribute is one of the regionalisation attributes. For a full list of the possible formats see the formatDate function.

Code examples Initialize a datepicker with the dateFormat option specified.

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

Get or set the dateFormat option, after init.

//getter
var dateFormat = $( ".selector" ).datepicker( "option", "dateFormat" );
//setter
$( ".selector" ).datepicker( "option", "dateFormat", 'yy-mm-dd' );
Sameera Thilakasiri
A: 

I am trying to change the format using this datepicker so I can add it to a database. None of these methods work for me and it is driving me insane.

I have tried:

jQuery(function() {


        jQuery.datepicker.formatDate({altFormat: 'yy-mm-dd' });
    });

and

jQuery(function() {


        jQuery.datepicker.formatDate({dateFormat: 'yy-mm-dd' });
    });

I do not understand where to put this

//getter
var dateFormat = $( ".selector" ).datepicker( "option", "dateFormat" );
//setter
$( ".selector" ).datepicker( "option", "dateFormat", 'yy-mm-dd' );
Michael
A: 

inside the jQuery script code just paste the code.

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

this should work.

sampath