Need suggestions to improve a potential error coming in Date conversion. In most of the cases when the date is provided in “MM/dd/yy” format - the “yy” is getting converted to any year that is being formed with some logics.
In my case, if the given date is like “02/15/13” or “02/18/56” - it is taking 02/15/2013 (which may be or may not be right. coz the DOB may be by 1913 as well). But, in the second case (02/18/56) - it should be for the previous year (02/18/1956) - where as Convert.ToDateTime(“MM/dd/yyyy”) takes the value as “02/18/2056” (which is future) - not correct.
As DOB may not occur in future case - how to make it take with only the less than current year? Anyone faced this issue? Solutions?
You could try setting your CultureInfo.CurrentCulture.Calendar.TwoDigitYearMax property to the current year. In this way, 2 digits years would be convert up to 2022, but a 23, for instance, would become 1923.
You’d have to research how to manipulate your CultureInfo in UiPath (search how to do it in C# and try replicating it in UiPath with Invoke Code or Assign activities), and the use it in your Convert.ToDateTime call.
However, this does not solve the issue of years equal or smaller than 22, where you will have not way of knowing where if it is 1922 or 2022.
This is a tricky one, maybe you if have the age of the person or other info you would be able to ge through it.
You can use: CDate(yourVariableName).toString("MM/dd/yyyy")
This solves the problem with the date “02/18/56”.
But your problem with the date “02/15/13”, where the year could be 1913 or 2013, I can see only one solution… which is update the records in the database to each corret year (with 4 digits) and also make sure that all new records will be inserted with the correct format (year with four digits).
If this solves your problem, kindly marks this post as solution to close this topic.
If you need extra help or/and if you have any question, please let me know
Just to make sure, are you date correct? I am asking this, because sometimes we are using virtual machines and the date and time are totally wrong, but we don’t even notice that. Perhaps, this CDate function take into account the machine’s date and time. So, if the year is 2088 and you ask to conver 49… it will return 2049
I tried this already and its providing the same result. For your previous system, I have EST in my system… which is 4.34 PM for me (with the same date). surprisingly, both the functionalities working for your case with the proper number and date? does it require any other settings or something like that?
Sorry, Microsoft SDK packages are not allowed with security. couldnt run this workflow as it requires the packages. cant go with invoke code option i believe.
Thanks @gustavo.cervelin for your time and help, This works! Appreciate your help on the same. @Lucas_Ferraz - Thanks for the solution and idea. I couldn’t invoke code due to my security issues.
Yes, But not sure why it varies with the previous results on yours and mine. Cdata and DateTime.Tostring and CultureInfo are most common try-outs for everyone. Not able to identify why it is producing different results.