Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6153489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:06:08+00:00 2026-05-23T20:06:08+00:00

I don’t know how to format a timestamp in VB so it gets inserted

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T20:06:08+00:00Added an answer on May 23, 2026 at 8:06 pm

    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:

    Dim sql As String = "UPDATE `Table` Set MyColumn= @DateValue WHERE ID= @ID"
    Using cn As New MySqlConnection("Your connection string here"), _
          cmd As New MySqlCommand(sql, cn)
    
        cmd.Parameters.Add("@DateValue", MySqlDbType.Datetime).Value = Now
        cmd.Parameters.Add("@ID", MySqlDbType.Int32).Value = 12345
    
        cn.Open()
        cmd.ExecuteNonQuery()
    End Using
    

    No formatting necessary. You could also just write the query this way:

    Dim sql As String = "UPDATE `Table` Set MyColumn= current_timestamp WHERE ID= @ID"
    

    But if you really insist on creating the string, it would look like this:

    Now().ToString("yyyy-MM-dd HH:mm:ss")
    

    using the format string instructions available here:
    http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Don't dismiss this as a newbie question! It's not, I'm not, I've tried everything,
(Don't know if this is strictly on-topic, but I don't see any better Stack
Don't know if this has been asked before, so point me to another question
I don't know how better to describe this. So take this example. var a
Don't know if this is the right place to ask this, but I will
Don't know what to do with this error. How to add data in SQL
Don't know if this is an eclipse specific problem but whenever I declare a
I don't know why this double json response are not successful: [{first_content:content,...}][{second_content:content,...}] So i
Don't know if this has been answered before. Have custom routes to users. If
I don't know if this has been asked before, but what i'd like to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.