MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesMySQL Help

Closed Thread
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 13th, 1999, 02:09 PM
dchrist
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
is there a way to set the default for a column to be the current date, without making that column a timestamp? i'm trying to provide the current date as the starting point for a column that will ultimately be changed. it seems that if mysql would accept multiple select statements, i should be able to do it with the following syntax:

ALTER table paintings ALTER column creation_date SET DEFAULT (select current_date());

any suggestions?

Reply With Quote
  #2  
Old September 13th, 1999, 06:59 PM
netman
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Use the now() function as your default:

ALTER TABLE paintings CHANGE creation_date creation_date DATETIME DEFAULT 'now()' not null';

now() gives the current date & time.


[This message has been edited by netman (edited 09-13-99).]

Reply With Quote
  #3  
Old September 13th, 1999, 08:11 PM
dchrist
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
that SQL statement doesn't work - it produces a default of 0000-00-00 00:00:00

Reply With Quote
  #4  
Old September 14th, 1999, 04:39 PM
netman
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Sorry... I tested this out with phpMyAdmin and phpMyAdmin automatically defaults the date to the current date.

Sorry.

Reply With Quote
  #5  
Old February 12th, 2010, 05:01 PM
buggers buggers is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2007
Posts: 45 buggers User rank is Sergeant Major (2000 - 5000 Reputation Level)buggers User rank is Sergeant Major (2000 - 5000 Reputation Level)buggers User rank is Sergeant Major (2000 - 5000 Reputation Level)buggers User rank is Sergeant Major (2000 - 5000 Reputation Level)buggers User rank is Sergeant Major (2000 - 5000 Reputation Level)buggers User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 14 h 42 m 29 sec
Reputation Power: 36
hi,
i believe i am having a similar problem... i need to set my default value to a function as well, but pma seems to have none of this. is there perhaps any way to have it done via the mysql console?

i need to set the default value of a timestamp field to CONVERT_TZ(CURRENT_TIMESTAMP, 'SYSTEM', '+2:00'), the following select statement works in PMA to change the timezone...
Code:
SELECT CONVERT_TZ(CURRENT_TIMESTAMP, 'SYSTEM', '+2:00') AS timestamp_SAST;


if i uncheck the timestamp mark, and insert the CONVERT_TZ function as used above into the default field in phpMyAdmin, it sets the default time to 0000-00-00 00:00:00 as yours does... :/ i guess one cannot add functions to default values, yet this page says you can:
http://www.modwest.com/help/kb6-256.html
Comments on this post
requinix disagrees: the thread is more than 9 years old. expected more from soneone with 43 posts

Last edited by buggers : February 12th, 2010 at 09:04 PM.

Reply With Quote
  #6  
Old February 12th, 2010, 06:46 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,371 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 6 h 29 m 6 sec
Reputation Power: 4140
buggers, please always check da manual before posting

as late as version 5, it says
Quote:
The DEFAULT clause specifies a default value for a column. With one exception, the default value must be a constant; it cannot be a function or an expression.


you're welcome

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

Reply With Quote
Closed Thread

Viewing: Dev Shed ForumsDatabasesMySQL Help > set DEFAULT to current date

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap