Results 1 to 2 of 2

Thread: Get Mysql Timestamp to textbox with your own format

  1. #1

    Thread Starter
    Addicted Member acidsnake's Avatar
    Join Date
    Feb 2008

    Thumbs up Get Mysql Timestamp to textbox with your own format

    here is my complete code for it

    Dim conn As New MySqlConnection(connStr)
                Dim reader As MySqlDataReader
                Dim cmd_date As New MySqlCommand("SELECT timestamp FROM allmessage WHERE status='sent' ORDER BY ID DESC LIMIT 0, 1", conn)
                reader = cmd_date.ExecuteReader
                While reader.Read
                    Dim i As Date = reader.GetDateTime("timestamp")
                    TextBox2.Text = Format(CDate(i), "yyyy-dd-MM HH:mm:ss")
                End While
    declare this function

    Public Function GetDateTime(ByVal ordinal As Integer) As DateTime

    End Function
    Last edited by acidsnake; Feb 27th, 2013 at 04:06 AM. Reason: correction

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002

    Re: Get Mysql Timestamp to textbox with your own format

    For all of the reasons in this thread: http://www.vbforums.com/showthread.p...in-the-textbox ... this is considered substandard coding... all it takes is one line:
    TextBox1.Text = i.ToString("yyyy-dd-MM HH:mm:ss") ... in fact you can skip using i all together....

    Textbox1.Test = reader.GetDateTime("timestamp").ToString("yyyy-dd-MM HH:mm:ss")

    Oh... and you'll want to do this with a scalar method... not a reader... you're only returning one date and one date only... use the ExecuteScalar function instead.

    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts


Click Here to Expand Forum to Full Width