I am trying to calculate age from dates. This works fine on the server computer but not on a particular client where it report error that "The string 07/21/2016
cannot be converted to a date". I found out that the locale of the server was set to en-US
and the client with error locale is set to en-UK
. I tried the code below to make the age calculation possible no matter the system locale but it has not worked.
Dim var as string = "07/30/2010"
Dim dob As String = Format(CDate(var & " 01:00:00"), "dd-MM-yyyy hh:mm:ss")
Dim dob1 As Date = DateTime.ParseExact(dob, "dd-MM-yyyy hh:mm:ss", System.Globalization.CultureInfo.InvariantCulture)
Dim todayDate As String = Format(Date.Now, "dd-MM-yyyy hh:mm:ss")
Dim todayDate1 As Date = DateTime.ParseExact(todayDate, "dd-MM-yyyy hh:mm:ss", System.Globalization.CultureInfo.InvariantCulture)
lblDob.Text = var & " (" & DateDiff(DateInterval.Year, dob1, todayDate1) - 1 & " yrs)"