WCF JSON Date Format to Javascript Nightmare

I wanted to share this little snippet that has saved my life many of time.  Those of you that run into this will appreciate this short line of javascript code that will make your dreams come true.

I am using the JQuery library for the service call, then handling the results with a little magic.

*Not your can handle the formatting on your service side, but If you don’t have access to the service this is an alternative method to accomplish the job.

Code Begin:


url: yourservicesaddress.svc/test,

data: {testid: _mytestid}//variables



var sdate = new Date(parseInt(result.mydatefield.substr(6)))
var formattedsdate = sdate.getFullYear() + “-” + (“0” + (sdate.getMonth() + 1)).slice(-2) + “-” + (“0” + sdate.getDate()).slice(-2);

//Then here you can use formatted date in a HTML 5 Date formatted text box.  Pretty //simple.



If you want to know about how you can integrate services check us out at ViviScape.  We provide custom software engineering solutions to make your life easier.





About Art Hicks

I am Business Owner/Applications Engineer that specializes in providing rich solutions to my clients and colleagues.
This entry was posted in .NET WCF Services, HTML5, jQuery and tagged . Bookmark the permalink.

1 Response to WCF JSON Date Format to Javascript Nightmare

  1. Pingback: JavaScript WCF Date Formats | Art Hicks Development

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s