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 :(

Recommended Answers

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>
Jump to Post

All 2 Replies

Member Avatar

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 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.