Search code examples
c#biztalkbiztalk-2010biztalk-mapper

Scripting Functoid for Date Formatting in Maps Biztalk 2010


In the Source Schema I have the Date in xs: date Time Datatype in the Destination Schema I have Date in String Datatype. When I map directly I get the output as "2013-10-21T00:00:00". But I want it "2013-10-21" in output.

I tried using the scripting but nothing worked like,

public String ConvertEndDate(string param1)
{
return DateTime.Parse(param1).ToString("yyyy-MM-dd");
}

public string convertHireDate(string Date1)
{
return DateTime.ParseExact(Date1, "YYYY-MM-DDThh:mm:ss", null).ToString("yyyy-MM-dd");
}

Can anybody help me to deal with this. Thanks in advance.


Solution

  • You would change INVALID DATE to something appropriate for your application.

     public string FormatDate(string inputDate)
        {
            System.DateTime strDate;
            if (System.DateTime.TryParseExact(inputDate, "yyyy-MM-ddTHH:mm:ss", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out strDate))
            {
                return strDate.ToString("yyyy-MM-dd");
            }
            return "INVALID DATE";
        }