Solved

Format YYYY-MM-DD Datepicker from jqueryui

Posted on 2009-04-04
3
490 Views
Last Modified: 2013-11-23
I am working with http://jqueryui.com/demos/datepicker/ to place in my html a datepicker so the user just click & select.

It works fine, but I need to have the text/input field return the format YYYY-MM-DD, its returning MM-DD-YYYY.

I have reviewed thier section on date format (http://jqueryui.com/demos/datepicker/#date-formats), but it seems that I need to have the date format window present in order to work.

How can I format the line to work strictly with: YYYY-MM-DD

Heres my code:

      $(function() {
        $("#From").datepicker();
        $("#format").change(function() { $('#From').datepicker('option', {dateFormat: $(this).val()}); });
            $("#To").datepicker();
        $("#format").change(function() { $('#To').datepicker('option', {dateFormat: $(this).val()}); });
      });
0
Comment
Question by:rayluvs
3 Comments
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 24067899
Without seeing all the code, it's hard to give you an exact answer and a code sample, but I can tell you the "best practices" way of dealing with date format conversions.

Use the functions strtotime() and date() to get this done.
http://us2.php.net/manual/en/function.strtotime.php
http://us2.php.net/manual/en/function.date.php

An example:
$iso_date = date('Y-m-d', strtotime('March 31, 2007'));

HTH, ~Ray
0
 
LVL 39

Accepted Solution

by:
Roger Baklund earned 500 total points
ID: 24067938
Have you tried this:

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

Author Comment

by:rayluvs
ID: 24068198
Thanx for the link Ray, I already have that...I'm looking for something for a user to click at, and the jqueryui works excellente!

cxr your solutions worked!  Thanx
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
These days socially coordinated efforts have turned into a critical requirement for enterprises.
This video teaches viewers about errors in exception handling.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question