I have formatted a string date into date format
by using

<script type="text/javascript">  
var st = "26-04-2013";
var pattern = /(\d{2})\-(\d{2})-(\d{4})/;
var dt = new Date(st.replace(pattern,'$3-$2-$1'));
alert(dt);
</script>

and it's output is

Fri Apr 26 2013 05:30:00 GMT+0530 (IST)

but I want out put as 2013-04-26

how can i do this in JS?
urgent please :(

Member Avatar for diafol

urgent please :(

Not to us. No need to say this - it's just annoying.

<script type="text/javascript">  
var st = "26-04-2013";
var pattern = /(\d{2})\-(\d{2})-(\d{4})/;
var dt = st.replace(pattern,'$3-$2-$1');
alert(dt);
</script>

Thanks a lot!
it worked
and I will take of it next time :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.