Mysql & Dates

I’m working with MySQL. Here is a test that mimics the issue:

  1. MySql date format
TextField2.Text = "2016-06-01" 

Displays as: 2016-06-01

  1. Convert date to short date
Dim d As New Date
d.SQLDate = TextField2.Text 
TextField2.Text = d.ShortDate

Displays as: 6/1/2016

  1. Save date back to MySQL
Dim Date As String = TextField2.Text

Dim d As New Date
d.Year = Val(Mid(Date,7,4))
d.Month = Val(Mid(Date,1,2))
d.Day = Val(Mid(Date,4,2))

TextField2.Text = d.SQLDate

Displays as: 0016-06-01 // Which is completely wrong.

So what is the proper way to handle dates in such a situation?

have you examined what SHORTDATE returns? bear in mind the user has complete control over its format, so do not ASSUME it will be what you expect.

and mid 7,4 = 16, so 0016 as year is correct
mid 1,2 = 6/ so 6 is correct
mid 4,2 is /2 so who knows what you get

seem you ASSUMED that shortdate was 06/01/2016 when in fact as you stated it was 6/1/2016

what not use PARSEDATE(textfield2.text,d)

PARSEDATE. I think that’s what I was looking for. Thanks

To avoid troubles with Mid, use NthField (with ‘/’ as separator)

NthField - cool. Thx