Click here to Skip to main content
15,498,506 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I want to retrive a date from database,
In Cspage I got the date like{06/10/2014 12:00:00 AM}
but I did't get it in Aspx Page
I use the code
JavaScript
$("#txtBilldate").val(data.d.lphBillDate);

Result is --/Date(1412533800000)/

How to change the above script to get the date like 03/06/2014 format.
Posted
Updated 19-Jun-14 3:18am
v2
Comments
ZurdoDev 19-Jun-14 8:34am    
Change data.d.lphBillDate to return string value of date/time or add a new property that will do it.
Thanks7872 19-Jun-14 9:22am     CRLF
You are asking such questions over and over again. You have already been told how to do it at your previous question. Further, it seems like you have misunderstood the layers and scripts. I strongly recommend you to have the basics clear first.
Swinkaran 19-Jun-14 21:38pm     CRLF
This is not a big magic, You can simply solve this in .cs file by DateTime dt = Convert.ToDateTime("06/10/2014 12:00:00 AM"); // if the database value is of DateTime type lblShortDate.Text= dt.ToShortDateString(); It's not appropriate to do this conversion in Javscript, any specific reason?

data.d.AddedDate is in json format.

use this function to convert date
$("#txtBilldate").val(Dateformat(data.d.lphBillDate));


function Dateformat(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
XML
<script type="text/javascript">
       function checkFutureDate(date) {
           var dtOrder = parseInt(date.substring(0, 2), 10);
           var monOrder = parseInt(date.substring(3, 5), 10);
           var yrOrder = parseInt(date.substring(6, 10), 10);

           var dateOrder = new Date(yrOrder, monOrder, dtOrder);

           if (dateOrder > new Date()) {

               alert("You cannot enter date later than today ");
               //  sender._selectedDate = new Date();
               // set the date back to the current date
               // sender._textbox.set_Value(sender._selectedDate.format(sender._format))

           }
       }
   </script>


First Divide Date And Then Arrange whatever date format you need...
 
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