Click here to Skip to main content
15,886,798 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
I have tried so far is $("#txtAddedDate").val(data.d.AddedDate);. But its output will be /Date(1415212200000)/. I need it in 03/06/2014 format.
Posted
Comments
KaushalJB 19-Jun-14 5:20am    
What query have you applied for retrieving date from db ??
My Doubt 19-Jun-14 5:24am    
I am using JSON for retrieving data. If it is int or string value will come. The problem is on date. It is declared as datetime.
Thanks7872 19-Jun-14 5:45am    
Then convert it to your required format and pass as a string.
KaushalJB 19-Jun-14 5:30am    
You can apply this :
String.Format("{0:d/M/yyyy}", AddedDate);
My Doubt 19-Jun-14 5:46am    
no its not working

data.d.AddedDate is in json format.

use this function to convert date
$("#txtAddedDate").val(jsonDateformat(data.d.AddedDate));

function jsonDateformat(date) {

jsonDate = date;
var d = new Date(parseInt(jsonDate.substr(6)));
var m, day;
m = d.getMonth() + 1;
if (m < 10)
m = '0' + m
if (d.getDate() < 10)
day = '0' + d.getDate()
else
day = d.getDate();
var formattedDate = m + "/" + day + "/" + d.getFullYear();
var hours = (d.getHours() < 10) ? "0" + d.getHours() : d.getHours();
var minutes = (d.getMinutes() < 10) ? "0" + d.getMinutes() : d.getMinutes();
var formattedTime = hours + ":" + minutes + ":" + d.getSeconds();
formattedDate = formattedDate + " " + formattedTime;
return formattedDate;
}
 
Share this answer
 
v2
Comments
My Doubt 20-Jun-14 2:11am    
Thanks its working
hi
in database query use convert function for fetching date as
CONVERT ( data_type [ ( length ) ] , expression [ , style ] )

e.g.

Convert(varchar(10),DateColumn,103)
 
Share this answer
 
In json the date format appears like this if you want to show the date in you specifird format you want to convert the date to string before it pass through json.Hope it helps
 
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