2

I have a string : 30/09/2010 and I'd like have 09/30/2010 hiw can I do this useing jQuery ?

Thanks,

1
  • Caveat: What do you do when the date comes as 04/12/2010 ? Switch or no switch? I'm assuming you always want to switch? Commented Sep 30, 2010 at 8:30

5 Answers 5

7

You no need Jquery it's very simple code :

var s_date = '30/09/2010'.split("/");
var org_date = s_date[1] + "/" + s_date[0] + "/" + s_date[2];
Sign up to request clarification or add additional context in comments.

Comments

4

There is a jquery datapicker at http://jqueryui.com/demos/datepicker/

It has a few static methods that may be of use to you, and would allow you to do something like:

var dstr = $.datepicker.formatDate('mm/dd/yy', 
                    $.datepicker.parseDate('dd/mm/yy', '30/09/2010'));

Comments

2

Actually not a jquery solution but datejs is a great framework for handling dates in javascript.

Comments

1

There is nothing in the jQuery library for that. You can use simple string operations in Javascript:

var s = '30/09/2010';

s = s.substr(3,2) + '/' + s.substr(0,2) + s.substr(6);

Comments

0

Try using the Date object:

var Stamp = '30/09/2010'.split("/");;
var Date = new Date(Stamp[2],Stamp[1],Stamp[0]); //(year,month,day)

Then use the format command like so:

Date.format("mm/dd/yy"); //Gives | 09/30/2010

Comments

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.