If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Default column value with current datetime

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-20-04, 11:28
mdd mdd is offline
Registered User
 
Join Date: Apr 2004
Posts: 2
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".
Reply With Quote
  #2 (permalink)  
Old 04-20-04, 11:49
guelphdad guelphdad is offline
Registered User
 
Join Date: Mar 2004
Posts: 440
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;
Reply With Quote
  #3 (permalink)  
Old 04-20-04, 12:00
mdd mdd is offline
Registered User
 
Join Date: Apr 2004
Posts: 2
Looking for Create Table - Not Select statement

Quote:
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
Reply With Quote
  #4 (permalink)  
Old 04-20-04, 13:49
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,609
I don't think that MySQL can do that yet. Default values have to be constants, you can't use functions.

-PatP
Reply With Quote
  #5 (permalink)  
Old 04-20-04, 16:00
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
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.

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On