Convert Date Time Format

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ssmeshack
    New Member
    • Jul 2008
    • 38

    Convert Date Time Format

    Hi all,

    Im have a problem here. Im using VWD 2008 (c#) and Mysql 2005. I dont know how to convert datetime data that i retrieve from mysql database to only date or time. Can anyone help me? Here is something that i tried to do.

    Code:
     Date1.Text = Convert.ToString(reader["FunDateTime"], (MMMM d, yyyy));
    //"MMMM d, yyyy",
    Time1.Text = Convert.ToString(reader["FunTime"], (HH:mm ss tt));
    //"HH:mm ss tt",
    but it didnt work even when i try to put format in of reader.
    Pls some one help me.

    Regards,
    Meshack
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Originally posted by ssmeshack
    Hi all,

    Im have a problem here. Im using VWD 2008 (c#) and Mysql 2005. I dont know how to convert datetime data that i retrieve from mysql database to only date or time. Can anyone help me? Here is something that i tried to do.

    Code:
     Date1.Text = Convert.ToString(reader["FunDateTime"], (MMMM d, yyyy));
    //"MMMM d, yyyy",
    Time1.Text = Convert.ToString(reader["FunTime"], (HH:mm ss tt));
    //"HH:mm ss tt",
    but it didnt work even when i try to put format in of reader.
    Pls some one help me.

    Regards,
    Meshack
    What data type is your FunTime column? DateTime?

    If so you should try to retrieve it first into a DateTime object...then calling the ToString function on that.

    (Please note that I'm really not great with C#, so there may be syntax errors in the following code...it's just there to give you an idea of what I'm talking about)
    Code:
    DateTime funTime = (DateTime) reader["FunTime"];
    Time1.Text = funTime.ToString(HH:mm ss tt));
    -Frinny

    Comment

    • ssmeshack
      New Member
      • Jul 2008
      • 38

      #3
      Originally posted by Frinavale
      What data type is your FunTime column? DateTime?

      If so you should try to retrieve it first into a DateTime object...then calling the ToString function on that.

      (Please note that I'm really not great with C#, so there may be syntax errors in the following code...it's just there to give you an idea of what I'm talking about)
      Code:
      DateTime funTime = (DateTime) reader["FunTime"];
      Time1.Text = funTime.ToString(HH:mm ss tt));
      -Frinny
      Thanks Frinny,

      Your idea is great. There is only one error that I figured out. The following code with correction. And FunTime column is DateTime object.

      Code:
      DateTime funTime = (DateTime) reader["FunTime"]; 
      Time1.Text = funTime.ToString("hh:mm ss tt");
      Thanks again for your help.

      -Meshack

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Glad to have helped :)

        Comment

        Working...