Mark C.
Mark C.

Reputation: 6450

Short Date from jQuery Datepicker

I'm trying to extract a short date ('m/d/yy') from jQuery Datepicker, but I have been unsuccessful. I've tried formatDate, dateFormat, parseDate, but still cannot get a short date format on the server side.

I created a Fiddle that I extracted and modified from one of the other threads on here.

It's my understanding that there's 2 different things we are dealing with in regards to jQuery UI Datepicker:

  1. The date that is formatted & shown as the value of the input
  2. The 'behind the scenes' value. I am trying to POST the date chosen as a short date, thus the format Wed May 13 2015 00:00:00 GMT-0400 (Eastern Daylight Time) doesn't work for me.

I understand that it's possible to convert the date to a string and format it that way, however I didn't know if it was possible within the jQuery UI library.

Upvotes: 1

Views: 494

Answers (1)

Jean-Paul
Jean-Paul

Reputation: 21150

Using jQuery UI, you can do:

$.datepicker.formatDate('m/d/yy', yourDate);     // where yourDate is the date variable

So in the jsFiddle this would become:

observable($.datepicker.formatDate('m/d/yy',$el.datepicker("getDate")));

See the demo (use datepicker to see the effect) for the results:

> jsFiddle DEMO

Upvotes: 1

Related Questions