Click here to Skip to main content
15,881,679 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi All.

I am getting date field from database in US-Format(MMddyyyy) but I need it to display is std date format i.e MM/dd/yyyy using javascript/jquery.

Example: If value from database is 7242014, then it will display 7/24/2014.

I have tried using substring but if months or days are 10 or more, then its not correct.

Please help.
Posted
Comments
Wombaticus 24-Jul-14 4:28am    
Most forms of SQL allow you to retrieve dates from the database pre-formatted as you want, which will be a much simpler solution.

"I have tried using substring but if months or days are 10 or more, then its not correct."

Try this............

If (parseint(MM) <10 ) {
MM = '0'+MM
}

C#
If (parseint(DD) < 10) {
DD = '0'+DD;
}
 
Share this answer
 
v2
Comments
Santosh K. Tripathi 25-Jul-14 1:56am    
Thanks :)
try this

XML
<script type="text/javascript">
    var d = new Date();
    var curr_date = d.getDate();
    var curr_month = d.getMonth() + 1; //Months are zero based
    var curr_year = d.getFullYear();
    document.write(curr_date + "/" + curr_month + "/" + curr_year);
</script>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900