Select to view content in your preferred language

Inserting Date

994
4
04-10-2013 05:09 AM
shabbirsiddiqui2
Deactivated User
Hi,

I am facing problem while inserting date through feature layer, Please check it and correct me where i am making the mistake.

    var startDate:String = "13/04/2013";
    var endDate:String = "20/04/2013";
    var sDate:Date= DateField.stringToDate(startDate,"DD/MM/YYYY");
    var eDate:Date= DateField.stringToDate(endDate,"DD/MM/YYYY");   
    var featureLayer:FeatureLayer = map.getLayer([configXML.FLayerDigging.DiggingServiceID].toString()) as FeatureLayer;   
    var newAtttrs:Object= new Object();           
    newAtttrs["COMPANY_NAME"] = txt_Company_name.text;   
    newAtttrs["START_DATE"]= sDate;
    newAtttrs["END_DATE"]= eDate;
    newAtttrs["OWNER"]=txt_owner.text;
    newAtttrs["TELEPHONE_NO"]=txt_phone_no.text;
    newAtttrs["MOBILE_NO"]=txt_mobile_no.text;
    newAtttrs["DIG_LENGTH"]=txtLength.text;
    newAtttrs["DIG_WIDTH"]=txtwidth.text;
    newAtttrs["DIG_DEPTH"]=txtDepth.text;
    newAtttrs["NOTES"]=txtrequestNote.text;
    var g:Graphic = new Graphic(geom,null,newAtttrs); 
    featureLayer.applyEdits(,null,null);

     Here the date filed is inserted as 11/04/2013 12:12:50 PM in START_DATE and 19/04/2013 12:12:50 PM as END_DATE , one day back date.

Please guide me with right path.

Thanks and Regards,
shabbir ahmad
Tags (2)
0 Kudos
4 Replies
RobertScheitlin__GISP
MVP Emeritus
Shabbir,

   Date are stored as UTC and thus you need to give your dates a time component and adjust to timezone offset.

Here is some code I use to set a date field attribute:

                            var bDate1:Date = new Date(DTPicker1.selectedDate.getFullYear(),DTPicker1.selectedDate.getMonth(),DTPicker1.selectedDate.getDate(),14,0,0,0);
                            offsetMilliseconds = bDate1.getTimezoneOffset() * 60 * 1000;
                            bDate1.setTime(bDate1.getTime() - offsetMilliseconds);
                            attribs.Begin_Date_Occ = bDate1.getTime();
0 Kudos
shabbirsiddiqui2
Deactivated User
Thanx Robert.

How can we get the date in correct format, when i did query on feature layer and try to display the  date field attribute, it displaying as -16894051200000 format instead of 26/08/1434.

Kind Regards,
Shabbir

Shabbir,

   Date are stored as UTC and thus you need to give your dates a time component and adjust to timezone offset.

Here is some code I use to set a date field attribute:

                            var bDate1:Date = new Date(DTPicker1.selectedDate.getFullYear(),DTPicker1.selectedDate.getMonth(),DTPicker1.selectedDate.getDate(),14,0,0,0);
                            offsetMilliseconds = bDate1.getTimezoneOffset() * 60 * 1000;
                            bDate1.setTime(bDate1.getTime() - offsetMilliseconds);
                            attribs.Begin_Date_Occ = bDate1.getTime();
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
shabbir,

   As I mentioned earlier ArcGIS Server is handling dates as UTC and thus they need to be converted from UTC number to actual dates. So convert the number to a date and then use the date objects functions to convert it to a string.
0 Kudos
omega_cancer
Frequent Contributor
0 Kudos