3

I am displaying a date which takes the following format;

Sun Feb 24 2013 00:00:00 GMT-0800 (Pacific Standard Time)

All what i want is Sunday February 24 2013. How could i format the above date to the format i want ?

var date = $(this).datepicker('getDate');
                  theDay = new Date(date.getFullYear(), date.getMonth(), date.getDate());
2
  • See this post formatting-a-date-in-javascript Commented Feb 15, 2013 at 20:35
  • Since you're already using the datePicker, $.datepicker.formatDate() does exactly what you wan't. Commented Feb 15, 2013 at 20:36

1 Answer 1

2

Using the DatePicker

$(this).datepicker({
    dateFormat: "DD MM d yy"
});

Example here: http://jsfiddle.net/eJseP/


Edited, by request:

<input type="text" id="myinputfield" value="" />
<script>
    $("#myinputfield").datepicker({
        dateFormat: "DD MM d yy"
    });
<script>
Sign up to request clarification or add additional context in comments.

3 Comments

Where do you want to display the string with the formatted date?
Whats the Id of your text field? if the textfield's id is "myinputfield" you should use "#myinputfield" instead of "this" when calling the function datepicker
Ok, so what you say is that i should get rid of my 2 lines (shown in the above post) and add your code instead ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.