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:

How to Delete an SSRS Report from SQL Server Reporting Services (SSRS) in D365FO

 In Microsoft Dynamics 365 Finance & Operations, SSRS reports are deployed to the SSRS server and stored in the ReportServer database. W...