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 > need to add a DATE column in a table

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-15-11, 08:29
prabhakaran66 prabhakaran66 is offline
Registered User
 
Join Date: Nov 2011
Posts: 3
Question need to add a DATE column in a table

i am using mysql-v5.1 and i want to add a DATE column in a table,

my requirement is,whenever i do insert a new row that column should update with current date and the date format should be like 'yyyymmdd' or 'yyyy-mm-dd' not like 'yyyy-mm-dd hh:mm:ss' .

so kindly tell me how to add a such a column.
Reply With Quote
  #2 (permalink)  
Old 11-15-11, 08:52
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
you are in luck
Code:
ALTER TABLE foo
ADD COLUMN bar TIMESTAMP
here's the explanation from da manual --
Quote:
A TIMESTAMP column is useful for recording the date and time of an INSERT or UPDATE operation. By default, the first TIMESTAMP column in a table is automatically set to the date and time of the most recent operation if you do not assign it a value yourself. You can also set any TIMESTAMP column to the current date and time by assigning it a NULL value. Variations on automatic initialization and update properties are described in Section 10.3.1.1, “TIMESTAMP Properties”.
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 11-16-11, 05:02
prabhakaran66 prabhakaran66 is offline
Registered User
 
Join Date: Nov 2011
Posts: 3
Thumbs down my requirement is not like this

if i add TIMESTAMP ,it will make column as "2011-11-16 15:13:00" but i need column as "2011-11-16"(only date).
Reply With Quote
  #4 (permalink)  
Old 11-16-11, 05:11
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
Quote:
Originally Posted by prabhakaran66 View Post
if i add TIMESTAMP ,it will make column as "2011-11-16 15:13:00" but i need column as "2011-11-16"(only date).
you can use DATE_FORMAT function to show only the date
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 11-16-11, 05:35
prabhakaran66 prabhakaran66 is offline
Registered User
 
Join Date: Nov 2011
Posts: 3
is it possible to define that in column description.
Reply With Quote
  #6 (permalink)  
Old 11-16-11, 05:47
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
no it isn't

your alternative is to use a DATE column, but you will have to remember to update the value yourself every time you insert or update a row
__________________
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