Codeunit 10 Type Helper TryEvaluateDate() error
Hi,
When I try to run TryEvaluateDate() it is giving me wrong date values below are the examples TryEvaluateDate('14/02/2018','dd/mm/yyyy','en-US',EvaluatedDateval); Result 14/01/2018 TryEvaluateDate('14/03/2018','dd/mm/yyyy','en-US',EvaluatedDateval); Result 14/01/2018 TryEvaluateDate('18/03/2018','dd/mm/yyyy','en-US',EvaluatedDateval); Result 18/01/2018
Because of this issue , Bank Account Reconciliation statement Import not working properly because import dates are wrong.
I tried to run same dll in dotnet to see if there is anything wrong , dot net also giving me above result.
please let me know if i'm doing anything wrong.
using System; using System.Globalization; using System.Threading;
public class Example { public static void Main() { DateTime dateValue; string dateString = "14/02/2018 6:32 PM";
if (DateTime.TryParseExact("14/02/2018","dd/mm/yyyy",
new CultureInfo("en-US"),
DateTimeStyles.None,
out dateValue))
{
Console.WriteLine("Converted '{0}' to {1}.",dateString, dateValue);
Thread.Sleep(10000);
}
else
{
Console.WriteLine("Unable to convert '{0}' to a date.", dateString);
Thread.Sleep(10000);
}
}
}
regards Mouli.K
Hi Mouli.K,
The issue is in the date format you are using: "dd/mm/yyyy". "mm" means minutes, not months. Try with "dd/MM/yyyy" instead. You can find more about the date formats here: https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings
Regards, David