How can I know if a date is a date? (VB.NET)

1

My intention is to know if the data that the user has entered, is date and that it is in the MySQL ( YYYY-MM-DD ) format. First I made a query with data type date to a table of Excel , but it turns out that when doing a test to see what the query was doing, I could notice that the date captured it with numerical values ...

Example: A date in my table is "08/16/2005" , but when I make the query, it returns a number ( 38580 in this case).

I do not understand, since it is clear that it is a date, and not a number. I know that in VB.NET we have the function IsDate , or the Date.TryParse ... I have already tried to identify them by making a condition, but apparently it does not work. How then could I do to identify if a value is of date type?

         If (Not Date.TryParse(valor(0), fecha)) Then
             MsgBox(valor(0))
             errores += 1
          End If
    
asked by TwoDent 16.08.2016 в 00:51
source

1 answer

1

Excel displays the dates with the format chosen by the user, but internally stores them as if they were numeric values .

From VB.NET you can use the function Date.FromOADate() to get the date corresponding to the value delivered by Excel . ( OA = OLE Automation )

    Date.FromOADate(38580)
    ' Resultado: #8/16/2005# '

    ' Para pasar al formato YYYY-MM-DD '
    Date.FromOADate(38580).ToString("yyyy-MM-dd")
    ' Resultado: "2005-08-16" '

To consult the custom formats for date, you can go to this msdn link .

    
answered by 16.08.2016 / 03:27
source