Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2004

    Unanswered: How to insert the date and time into a data base while doing routine inserts.

    I have several fields set up in mysql data base and one of them is set to take date data. However I cannot figure how to format it so the date field will accept it.

    $mydate = date("F j, Y");

    $mytime = date("g:i a");

    $query = "INSERT INTO confirm (id, amtitle, code, mydate, mytime) VALUES ('$userid', '$amtitle', '$code', '$mydate', '$mytime')";

    I tried something like this, but it would not accept it and came back with a format like 0000-00-00
    So i changed my date field to characters and it will then hold the date, but not being a date field it cannot be manipulated as a date field of course.

  2. #2
    Join Date
    Nov 2004
    out on a limb
    Provided Answers: 59
    well first off i'd stroe the date and time as a single column
    I'd then make sure the format of the date/time is set correctly for the MySQL engine in the PHP script

    IIRC the datatype in the MySQL is datetime NOT Timestamp
    the date time format is iso date ie YYYY/MM/dd @ HH:MMS
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Apr 2002
    Toronto, Canada
      INTO confirm 
         ( id
         , amtitle
         , code
         , mydatetime ) 
         ( '$userid'
         , '$amtitle'
         , '$code'
         , CURRENT_TIMESTAMP ) | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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