Results 1 to 4 of 4

Thread: retrieve CURRENT_TIMESTAMP value with MySQL

  1. #1
    Join Date
    Apr 2009
    Posts
    65

    retrieve CURRENT_TIMESTAMP value with MySQL

    How to retrieve CURRENT_TIMSTAMP using MySQL query, this is because i want to retrieve all the the records and the time during which the records were edited, this is just to keep track of which records have been modified or changed so please let me know if anyone aware it. I think this would be one kind of logs which we could maintain for the records we have edited.

  2. #2
    Join Date
    Jan 2009
    Posts
    140

    Re: retrieve CURRENT_TIMESTAMP value with MySQL

    I will provide an trigger example that you apply in your application which will trigger as per the time set and provides you the records detail, but this will be an simple idea about how to get the data retrieval if you require some additional field to be retrieve add your own fields as per the table fields.

    Code:
    CREATE TRIGGER t_ins BEFORE INSERT ON t
    FOR EACH ROW SET NEW.date_expire= ADDDATE(CURDATE(),INTERVAL 1 MONTH);

  3. #3
    Join Date
    Jan 2009
    Posts
    143

    Re: retrieve CURRENT_TIMESTAMP value with MySQL

    As shown in the following table you need to assign the table details and the table parameters and then you need to set the timestamp on the fields you want to have the timestamp.

    Code:
    CREATE TABLE IF NOT EXISTS `staff` (
      `idstaff` mediumint(8) unsigned NOT NULL auto_increment,
      `name` varchar(45) default NULL,
      `username` varchar(45) NOT NULL,
      `password` varchar(45) default NULL,
      `role` varchar(20) default NULL,
      `lastchange` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
      PRIMARY KEY  (`idstaff`,`username`)
    ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;

  4. #4
    Join Date
    Mar 2008
    Posts
    232

    Re: retrieve CURRENT_TIMESTAMP value with MySQL

    The reason it uses DATETIME is because MySQL has very special meanings for "TIMESTAMP" and you may use`entry_date` TIMESTAMP default CURRENT_TIMESTAMP which is supported by MySQL. As for the parsing of CURRENT_TIMESTAMP, we can add an exception that support for an default expression mentioned above.

Similar Threads

  1. Replies: 4
    Last Post: 13-01-2011, 01:08 AM
  2. Using Ajax to Retrieve Data from a MySQL Database
    By warthogweb in forum Software Development
    Replies: 1
    Last Post: 19-11-2010, 10:46 PM
  3. Replies: 3
    Last Post: 19-07-2010, 04:23 PM
  4. mysql config file in MySQL
    By Netorious in forum Software Development
    Replies: 4
    Last Post: 18-03-2010, 09:43 PM
  5. Replies: 3
    Last Post: 07-11-2009, 09:36 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,978,527.72113 seconds with 17 queries