none
ddMMMyy to YYYYMMDD in BizTalk Map RRS feed

  • Question

  • I have field in input with datetype string and contains Date in format (ddMMMyy). Ineed to transform the date into (YYYYMMDD) format and assign into string field in destination.

    How to achieve this?

    Tuesday, June 7, 2016 7:48 PM

Answers


  • You have to use Inline C# in scripting functoid.

    Code as below:

    public string ConvertDate(string Date)
            {
                
                string formatString = "ddMMMyy";
                string stringDate;
                DateTime outDate;
                if (!DateTime.TryParseExact(Date, formatString, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out outDate))
                {
                    stringDate = "InvalidDate";
                }
                else
                {
                    stringDate = outDate.ToString("yyyyMMdd");
                }
    
                return stringDate;
            }
    Note: I am assuming that if parsing fails you will pass a string "InvalidDate", ask the business what they want in case of parsing failure and change accordingly.


    Rachit Sikroria (Microsoft Azure MVP)

    • Marked as answer by Satish.kumar1 Wednesday, June 8, 2016 2:44 AM
    Tuesday, June 7, 2016 8:06 PM
    Moderator
  • Hi Satish,

    What have you tried?

    You have to use DateTime.TryParseExact and then do DateTime.ToString("yyyyMMdd") to convert into yyyyMMdd format.


    Rachit Sikroria (Microsoft Azure MVP)

    Tuesday, June 7, 2016 7:57 PM
    Moderator

All replies

  • Hi Satish,

    What have you tried?

    You have to use DateTime.TryParseExact and then do DateTime.ToString("yyyyMMdd") to convert into yyyyMMdd format.


    Rachit Sikroria (Microsoft Azure MVP)

    Tuesday, June 7, 2016 7:57 PM
    Moderator

  • You have to use Inline C# in scripting functoid.

    Code as below:

    public string ConvertDate(string Date)
            {
                
                string formatString = "ddMMMyy";
                string stringDate;
                DateTime outDate;
                if (!DateTime.TryParseExact(Date, formatString, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out outDate))
                {
                    stringDate = "InvalidDate";
                }
                else
                {
                    stringDate = outDate.ToString("yyyyMMdd");
                }
    
                return stringDate;
            }
    Note: I am assuming that if parsing fails you will pass a string "InvalidDate", ask the business what they want in case of parsing failure and change accordingly.


    Rachit Sikroria (Microsoft Azure MVP)

    • Marked as answer by Satish.kumar1 Wednesday, June 8, 2016 2:44 AM
    Tuesday, June 7, 2016 8:06 PM
    Moderator