Click here to Skip to main content
15,897,315 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear The Code Project,
I am trying to write a simple code function for my reporting services, which is basically converting number to date. please see below for the code:
However i have also some empty rows in my table, so when i runt the report with the following code i get some rows have Error ([rsRuntimeErrorInExpression] The Value expression for the field ‘aaa’ contains an error: Index and length must refer to a location within the string.
Parameter name: length), how can i fix my code?
Can anyone help me?
VT

Public Function ConvertDate(ByVal value As String) As Date

' Converts a date in YYYYMMDD format to DD/MM/YYYY format.

Dim theYear As String = value.SubString(0, 4)
Dim theMonth As String = value.SubString(4, 2)
Dim theDay As String = value.SubString(6, 2)
Dim result As String = theDay & "/" & theMonth & "/" & theYear
return CDate(result)
End Function
Posted

1 solution

Why are you not using DateTime.TryParse or DateTime.TryParseExact?

That would help you getting rid of this function by one line of code.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900