0

I am calling my server code to return json data

$.ajax({
type: "POST",
url: "myurl",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (appdata) {

        var testdata = $.parseJSON(appdata.d);

        console.log(testdata);

        $.each(testdata, function (index, appt) {
        //console.log(appt.PRODUCTID);// works fine
        //console.log(appt.ENTRYDATE);// works fine
        // var starttime=??
    }
});

Here is the console.log(testdata) output

[Object, Object]

0: Object

  PRODUCTID : "51",
  ENTRYDATE : "2013-02-13T12:30:00",
  CATEGORYID : null

__proto__:Object

1: Object

  PRODUCTID : "52",
  ENTRYDATE : "2013-02-13T12:40:00",
  CATEGORYID : null

__proto__: Object
  length: 2
__proto__: Array[0]

How can I extract the time information from ENTRYDATE like (12:30) from the first object's entrydate 2013-02-13T12:30:00

Edit

console.log(appt.ENTRYDATE) works fine, the issue only is how to extract time information from appt.ENTRYDATE

3 Answers 3

2

You can extract the time information by using javascript split

 var datetime = appt.ENTRYDATE;
 var datedata = datetime.split("T");
 var datevalue = datedata[0]; //date value
 var timevalue = datedata[1]; //time value
Sign up to request clarification or add additional context in comments.

Comments

1

How can I extract the time information from ENTRYDATE like (12:30)

to this: http://jsfiddle.net/Q4vsk/

$.each(testdata, function (index, appt) {
    var $getTime = appt.ENTRYDATE;// works fine
    var $Time = $getTime.substr($getTime.indexOf('T')+1).slice(0, -3);
    console.log($Time); // output will be: 12:30, 12:40
});

Comments

1

This might be the worst answer but you could try split

var starttime="2013-02-13T12:40:00";   // this comes from appt.ENTRYDATE 
var n=starttime.split("T"); 
console.log(n[1]);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.