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:

Import and Export file from BLOB storage Account(Azure) in D365 F&O using X++

  Import and Export file from BLOB storage Account in D365 F&O using X++ Import: /// <summary> /// MKInventQualityOrderLineService...