How to compare two dates FORMATS for saving to DB

前端 未结 3 2083
慢半拍i
慢半拍i 2020-12-11 07:56

I want to compare two date formats and return \"false\" when two formats are not equal.

For example, I get two da

3条回答
  •  死守一世寂寞
    2020-12-11 08:26

    The question is confusing because it asks two separate questions. This is an answer to the second question which asks for a function that will test whether a date string is in the format "yyyy-MM-dd". It uses the DateTime.ParseExact method to test whether the string is in the required format.

    Function IsCorrectDateFormat(testDate As String) As Boolean
        Dim myDate As DateTime
        Return DateTime.TryParseExact(testDate, "yyyy-MM-dd",
                                      System.Globalization.CultureInfo.InvariantCulture,
                                      System.Globalization.DateTimeStyles.None, myDate)
    End Function
    

提交回复
热议问题