Wednesday, 22 May 2013

EP: C# code to convert string (Date) to Date time and also it can be used for multiple Zones (Culture).

The below code is used to convert string (Date) to Date time and also it can be used for multiple Zones (Culture). 

 ///
    /// This method is used to convert date to date time.
    ///

    ///
    /// returns datatime
    private DateTime ConvertToDateTime(string strDateTime)
    {
       
        IFormatProvider culture = System.Threading.Thread.CurrentThread.CurrentCulture;
        DateTime dtFinaldate;
       
        try
        {
            dtFinaldate = DateTime.Parse(strDateTime, culture, System.Globalization.DateTimeStyles.AssumeLocal);
        }
        catch (FormatException)
        {
             culture = new System.Globalization.CultureInfo("fr-FR", true);
             dtFinaldate = DateTime.Parse(strDateTime, culture, System.Globalization.DateTimeStyles.AssumeLocal);
        }
        return dtFinaldate;

    }

No comments:

Automating Credit Card Transaction File Transformation Using Azure Logic Apps and D365 Finance & Operations

  Modern ERP environments increasingly depend on reliable, automated integration processes. After recent platform updates, certain internal ...