Convert 8 Char Date to a Formatted Date String
Posted by Chad Humphries over 2 years ago
Converts a date formated as YYYYMMDD to a MM/DD/YYYY format


Public Function GetFormattedDate(ByVal s8CharDate As String) As String
  Dim sMonth, sDay, sYear As String
    If (IsDBNull(s8CharDate) = True) Then Return ""
    If (IsNothing(s8CharDate)) Then Return ""
    If (s8CharDate.Length >= 8) Then
      If (s8CharDate.Substring(4, 2) < 10) Then : sMonth = s8CharDate.Substring(5, 1)
      Else : sMonth = s8CharDate.Substring(4, 2) : End If
      If (s8CharDate.Substring(6, 2) < 10) Then : sDay = s8CharDate.Substring(7, 1)
      Else : sDay = s8CharDate.Substring(6, 2) : End If
      Return sMonth & "/" & sDay & "/" & s8CharDate.Substring(0, 4)
    End If
    Return ""
End Function

Language VB.NET / Tagged with datetime