[CLOSED] Date is a string instead of Date object

  1. #1

    [CLOSED] Date is a string instead of Date object

    Checkout this following sitation pls:

    Store:
    <ext:Store ID="stoCandidate" runat="server" RemoteSort="true" OnRefreshData="Store_Refresh">
            <Reader>
                <ext:JsonReader IDProperty="CandidateId">
                    <Fields>
                          ....
                    <ext:RecordField Name="EngtThruDate" Type="Date" ServerMapping="EngtThruDate" />
                    <ext:RecordField Name="DaysToExpire" Type="Int">
                            <Convert Fn="getDaysToExpire"   />
                        </ext:RecordField>
                   </Fields>
                </ext:JsonReader>
            </Reader>
            .....
    JS:
    
               // returns date difference in days
                var getDateDiffDays = function(first_date, second_date) {
                    //round it to prevent daylight savings issues (missing or extra hour)
                    return Math.round((first_date - second_date) / (1000 * 60 * 60 * 24));
                }
    
    
    
                var getDaysToExpire = function(value,record){
                
                    var curDate = new Date();
                    return getDateDiffDays(record.EngtThruDate, curDate);
                
                
                }
    The example above returns 'NaN' value for "DaysToExpire" column!?

    Why?

    I've needed to get Date object like this:

    var getDaysToExpire = function(value,record){
                
                    var curDate = new Date();
                    return getDateDiffDays(Date.parseDate(record.EngtThruDate, "Y-m-dTH:i:s.u"), curDate);
                
                
                }

    Thanks.
    Last edited by Daniil; Feb 07, 2012 at 4:57 PM. Reason: [CLOSED]
  2. #2
    Hi,

    There is a raw record's data within a Convert handler. "A raw data" means a data which comes from a server. A date object comes from a server as a string. So, you have a string within a Convert handler.

    I can't see any way to resolve the problem apart from the one you've already applied - parsing a string manually.

Similar Threads

  1. [CLOSED] JSON object property: convert to Date value
    By supera in forum 2.x Legacy Premium Help
    Replies: 4
    Last Post: Jun 14, 2012, 2:50 PM
  2. Replies: 3
    Last Post: May 09, 2012, 4:28 PM
  3. Replies: 2
    Last Post: Apr 23, 2012, 12:47 PM
  4. Replies: 1
    Last Post: Jun 29, 2011, 3:00 AM
  5. Replies: 4
    Last Post: Nov 08, 2010, 6:00 AM

Tags for this Thread

Posting Permissions