SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Nov 2007
    Posts
    120
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    when doing INSERT automatically add NOW

    Hey,

    I'm wondering if its possible when I do an INSERT to automatically add the DATETIME/NOW() ?

    Currently I'm doing it through my script itself

    Code MySQL:
    INSERT INTO table (id, userid, currentDate)
    VALUES (1, 1, NOW())

    What I'm looking for is something like this:

    Code MySQL:
    INSERT INTO table (id, userid)
    VALUES (1, 1)

    Not sure? thanks!

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,017
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    read up on the DEFAULT VALUE CURRENT_TIMESTAMP option in the CREATE TABLE statement in the manual, it gives an example
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


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
  •