I thought that if a timestamp (i.e. timestamp(4) ) is specified, whenever a record is inserted into the database, the field will automatically insert the current date. I read some more on this topic, but not sure what would be the best way to attack this problem.

Any help would be greatly appreciated.

Arpi

    This is how I'd do it.

    Get the date and in your insert statement include the field to insert the date into, and then put the date variable into that field

    ie

    $month = date ("F");
    $daynumber = date ("j");
    $daysuffix = date ("S");
    $year = date ("Y");
    $date = ("$daynumber$daysuffix $month $year");
    $query = "INSERT INTO table (date) VALUES ('$date')";
    $result = mysql_query($query);

    should work.

    Of course that will put in say

    19th August 2001 for today, but what you want it to insert can easily be set, see the link below for PHP date() function information.

    http://www.php.net/manual/en/function.date.php

      • [deleted]

      In your database, create a table of the timestamp type.
      Whenever a row is inserted or changed in any way, the timestamp value will be updated to the current date and time.

      If you want to insert the current time in a column, use the now() keyword in SQL:

      UPDATE table SET column=now()

        3 months later

        Arpi,

        The way that IO think you are looking for is to when createting the TIMESTAMP column, set the Default to be 'now()' This way ..
        whenever you do an insert and leave out that column, it will auto insert the timestamp for you..
        eg: (this is an Audit Log I use)

        sal_id int(4) PRI NULL auto_increment
        fk_sai_id int(4)

        sal_audit_date timestamp(14) YES Def.=now()
        sal_comment text

        INSERT INTO system_audit_log (fk_sai_id, sal_comment) VALUES (1, 'Bad thing happened');

        And i get back ..
        +--------+-----------+----------------+-------------------------------------+
        | sal_id | fk_sai_id | sal_audit_date | sal_comment |
        +--------+-----------+----------------+-------------------------------------+
        | 255 | 1 | 20011107060318 | Bad thing happened |
        +--------+-----------+----------------+-------------------------------------+

        Hope this helps

          • [deleted]

          Uhm.. didn't I say timestamps get the current time automatically nomatter what you do?

            Write a Reply...