How to ensure a date is valid?

Viewed 118

My code below assigns certain parts of a file name to a variable. What is important here is the variable "yearandmonth" which is a string formatted as "yyyy-mm"

Dim fileparts() As String
            Dim delimiter As String = " - "
            Dim company As String
            Dim type As String
            Dim bank As String
            Dim bankaccount As String
            Dim yearandmonth As String 
            Dim fileyear As String
            Dim filemonth As String

            fileparts = Split(localFileName, delimiter)
            company = fileparts(0)
            type = fileparts(1)
            bank = fileparts(2)
            bankaccount = fileparts(3)
            yearandmonth = Left(fileparts(4), 7) ' RESULTS IN A STRING THAT WILL LOOK LIKE "yyyy-mm"
            fileyear = Left(yearandmonth, 4) ' results in "yyyy"
            filemonth = Right(yearandmonth, 2) ' results in "mm"

How can I ensure that the output from "yearandmonth" is a valid year, month and that it contains the "-"?

1 Answers
Related