TheBoubou
TheBoubou

Reputation: 19903

String date and string manipulation with jQuery

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

Thanks,

Upvotes: 2

Views: 4925

Answers (5)

RobertPitt
RobertPitt

Reputation: 57268

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

Upvotes: 0

zod
zod

Reputation: 2788

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'));

Upvotes: 4

john misoskian
john misoskian

Reputation: 584

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];

Upvotes: 7

Guffa
Guffa

Reputation: 700372

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);

Upvotes: 1

Darin Dimitrov
Darin Dimitrov

Reputation: 1038890

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

Upvotes: 2

Related Questions