locked
How to put Datetime in MySQL Database RRS feed

  • Question

  • User928149956 posted
    Thanks your everyone! Anyone know how to put the format #mm/dd/yyyy hh:mm:ss# into the MySQL database~~ Thanks!!
    Monday, July 22, 2002 12:02 PM

All replies

  • User1534471677 posted
    JackNet, I'm not sure why you would want to change the datetime format in MySQL since it is using the ISO standard, which will become the furture standard for all databases. (ISO Standard is YYYY/MM/DD HH:MM:SS) .net will take the ISO entry in a MySQL database and convert into the American Standard and of course you can always format the date with: 'Long Date Format Dim strDate As String = String.Format("{0:D}", DateTime.Now) 'Short Date Format Dim strDate As String = String.Format("{0:d}", DateTime.Now) Another option is if you don't "trust" .net to change your dates, you can always do it with SQL like so: SELECT DATE_FORMAT('2002-07-23 09:23:00','%m %d %Y ') AS RightNow; Cheers...
    Tuesday, July 23, 2002 9:31 AM
  • User928149956 posted
    I have tried to insert Dim ToDate As Date ToDate.Now() into MySQL DateTime, Timestamp but there still have error occurred. I haven't any method to solved that. But ASP.NET only show out dd/MM/yyyy hh:mm:ss format!!! (Yes, I also want to use the ISO standard, but I can't do it~~~ ! Could you help me~~??? Thanks the nice guy~~~^^)
    Tuesday, July 23, 2002 12:54 PM
  • User1534471677 posted
    JackNet, When inserting a date value into MySQL you will want to format the date with a String.Format function. For example you would use String.Format("{0:u}", DateTime.Now) to tell .net to change the date to ISO format... SQL Insert Example below: strSQL = "INSERT INTO MyTable(EntryDate) " strSQL += "VALUES(" strsQL += "'" & String.Format("{0:u}", DateTime.Now) & "')" objCmd = New ODBCCommand(strSQL, objConn) objConn.Open() objCmd.ExecuteNonQuery() objConn.Close() Cheers...
    Wednesday, July 24, 2002 1:48 PM
  • User928149956 posted
    Thanks~~alcoelho~~~~ That's okay! It's hard to understand about the documentation. If not you, I think I can't do that!!!! Thank you!!!! ^^ ~~~~ :D
    Thursday, July 25, 2002 7:28 AM
  • User928149956 posted
    I have a better idea formatting datetime now. Thank you! Datetime.Now().ToString("yyyy/MM/dd hh:mm:ss") It's much more convenient to control. Thanks for reply.!
    Friday, April 18, 2003 1:45 PM
  • User700495156 posted
    u r the best! is working!
    Thursday, November 13, 2003 10:15 PM
  • User-132184791 posted

    i also got same problem

    thank man solve my problem too 

     

    ErnestKok u malaysia also ?? kaki rang

    Wednesday, March 28, 2007 2:03 AM
  • User-1886564955 posted

    thanks for this : Datetime.Now().ToString("yyyy/MM/dd hh:mm:ss")

    it helps me a lot ^^

    Wednesday, June 22, 2011 12:11 AM
  • User1805528910 posted

    MySql does not allow to save the format you are asking. YOu need to store the value in its format yyyy/MM/dd hh:mm:ss.

    What youi can do store the value

    Datetime.Now().ToString("yyyy/MM/dd hh:mm:ss")

    When retriving the value from database format it as you want...

    Convert.ToDateTime(YourResultSet).ToString("mm/dd/yyyy hh:mm:ss");

    I hope this will help you.

    Wednesday, June 22, 2011 12:42 AM