Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2004
    Posts
    2

    Unanswered: Default column value with current datetime

    Any one know how to create a table where one of the column is of type datetime and default vaule is aggined as now() or someting like that so that every toime you insert any a new record to that table, the current date time value is automatically inserted as "MM/DD/YYYY HH:MMS".

  2. #2
    Join Date
    Mar 2004
    Posts
    480
    use timestamp instead and then you can use date_format to retrive the info in whatever order you want.

    see the Date_and_time_functions area in the manual for more info but here is an example:

    say your timestamp column is timesold

    SELECT date_format(timesold,'%m/%d/%y %h:%i:%s') as mytime FROM mytable;

  3. #3
    Join Date
    Apr 2004
    Posts
    2

    Looking for Create Table - Not Select statement

    Originally posted by guelphdad
    use timestamp instead and then you can use date_format to retrive the info in whatever order you want.

    see the Date_and_time_functions area in the manual for more info but here is an example:

    say your timestamp column is timesold

    SELECT date_format(timesold,'%m/%d/%y %h:%i:%s') as mytime FROM mytable;
    I am looking for create table statement & how to define the default date entry in correct format. not a select statement.
    -thanks

  4. #4
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    I don't think that MySQL can do that yet. Default values have to be constants, you can't use functions.

    -PatP

  5. #5
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    patp does mysql

    dbforums Message
    You have included too many images in your signature or in your previous post. Please go back and correct the problem and then continue again.

    rudy.ca | @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
  •