How to inser DateTime into the MySql Database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • santosh95808
    New Member
    • Oct 2008
    • 2

    #1

    How to inser DateTime into the MySql Database

    Hi friends,

    I am finding some difficulties in the inserting date time into the database.

    I am not able to convert the datetime into the mysql's Date Time format i.e.
    'yyyy/mm/dd hh:mm:ss'

    pls anybody can help me
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    DateTime is not kept as a string, that's just how it is shown to you.
    You should be able to use a Paramater and set the type to DateTime, then add the datetime object to it.

    Example:
    [code=C#]
    DateTime EDate = DateTime.Now;
    com.Parameters. Add("@EndDate", SqlDbType.DateT ime);
    com.Parameters["@EndDate"].Value = EDate;
    [/code]

    Comment

    • santosh95808
      New Member
      • Oct 2008
      • 2

      #3
      Originally posted by Plater
      DateTime is not kept as a string, that's just how it is shown to you.
      You should be able to use a Paramater and set the type to DateTime, then add the datetime object to it.

      Example:
      [code=C#]
      DateTime EDate = DateTime.Now;
      com.Parameters. Add("@EndDate", SqlDbType.DateT ime);
      com.Parameters["@EndDate"].Value = EDate;
      [/code]


      But i want to know how to write a command like insert because i am inserting so many things into the table and among those DateTime is one feild....

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        So write your command using the parameter?



        Comment

        Working...