I don’t know how to format a timestamp in VB so it gets inserted into the MYSQL database in this format:
YYYY-MM-DD 00:00:00
I tried:
Dim timestamp As Date = TimeValue(Now)
It formats it as 0001-01-01 12:33:38 — This would be correct if the yyyy-mm-dd was actually the correct date.
You missed the point.
Real timestamps in sql databases are never formatted
YYYY-MM-DD 00:00:00. That’s just how they are displayed in a query or data window. These values are actually stored in a binary format that is often not human readable, though mysql might still use unix time.The point is that you don’t even need to know for certain what the actual format is. This should be handled by your database connection provider, rather than formatting it yourself. Inserting/updating a database timestamp correctly for mysql from VB.Net should look something like this:
No formatting necessary. You could also just write the query this way:
But if you really insist on creating the string, it would look like this:
using the format string instructions available here:
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx