Search This Blog

Tuesday, October 25, 2011

Convert str to Date while importing from XML into AIF

When we are importing the date from xml to AIF we cannot convert that string to date using str2date().
The following function is used to convert from str to date.

Date ConvertXMLStrToDate(str _xmlValue)
{
    System.DateTime                 netDttm;
    str strTransDateTime;
    utcdatetime                     TransDateTime;
    ;
    new  InteropPermission(InteropKind::CLRInterop).assert();
    netDttm = System.DateTime::Parse(_xmlValue);
    TransDateTime=Global::utcDateTime2SystemDateTime(netDttm);
    return dateTimeUtil::date(TransDateTime);
}

Call from job

static void krishh_ConvertXmlStrToDate(Args _args)
{
date datevar;
System.DateTime                 netDttm;
str strTransDateTime;
utcdatetime                     TransDateTime;
EDSA_CreateSalesOrder createsales;
;
createsales=new EDSA_CreateSalesOrder();
strTransDateTime='2011-08-25 00:00:00';
datevar=createsales.ConvertXMLStrToDate(strTransDateTime);
}

1 comment:

  1. Hi Krishna,

    I am using below piece of code.The date I m expecting is 20130101 but the output is 20121231.
    Any ide what is going wrong.

    System.DateTime xmlDateTime, myDateTime ;
    utcDateTime TransDateTime;

    ;

    xmlDateTime= System.DateTime::Parse('2013-01-01T00:00:00+0100');
    TransDateTime=Global::utcDateTime2SystemDateTime(xmlDateTime);
    print dateTimeUtil::date(TransDateTime);
    pause;

    Thanks,
    Ismail

    ReplyDelete

Thanks for visiting my blog,
I will reply for your comment within 48 hours.

Thanks,
krishna.