Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > MySQL
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
MySQL General discussion about the MySQL database.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the MySQL section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 8th, 2003, 05:41 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default Default Value for DATETIME column


Hello All there,

I am looking for defining default value for a DATETIME column in MYSQL. As I read from the online manual, it says that, the defaul values for a column while creating a table, should always be constant, something like NOW() or CURRENT_TIME cannot be given. But is there a way to have the current date/timestamp stored in to the table in the way of defining DEFAULT VALUE everytime a record is inserted to the table.

Thanks for the help in advance.

Regards,
Vijay G
__________________
- Vijay G
Reply With Quote
  #2 (permalink)  
Old September 12th, 2003, 01:22 AM
Registered User
 
Join Date: Sep 2003
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
There is no way to insert current date or time in MySQL while creating tables.U have to insert the values urself. I way not got anyway. I have tries different queries to insert into the table current date or time.
thanx

Reply With Quote
  #3 (permalink)  
Old September 12th, 2003, 01:33 PM
Friend of Wrox
Points: 2,570, Level: 21
Points: 2,570, Level: 21 Points: 2,570, Level: 21 Points: 2,570, Level: 21
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: San Diego, CA, USA
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Timestamp fields default to the current time for UPDATE and INSERT queries, but not DATE or DATETIME fields. If you need this added convenience, use a timestamp field.

Read up on the different types here:
  http://www.mysql.com/doc/en/DATETIME.html


Take care,

Nik
http://www.bigaction.org/
Reply With Quote
  #4 (permalink)  
Old September 17th, 2003, 09:47 PM
Registered User
 
Join Date: Sep 2003
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You may use 'getdate()' as a default value for datetime columns in SQL Server.

Reply With Quote
  #5 (permalink)  
Old September 18th, 2003, 01:04 AM
Friend of Wrox
Points: 2,570, Level: 21
Points: 2,570, Level: 21 Points: 2,570, Level: 21 Points: 2,570, Level: 21
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: San Diego, CA, USA
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That doesn't help much as this is a MySQL forum, though.. =(

Take care,

Nik
http://www.bigaction.org/
Reply With Quote
  #6 (permalink)  
Old August 7th, 2009, 04:14 PM
Registered User
 
Join Date: Aug 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default TIMESTAMP field works perfectly

Thanks! Using the timestamp field worked great for capturing the date/time of the insert event.
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 Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
getting default value of a column elygp Need help with your homework? 1 June 18th, 2008 02:41 PM
GridView Hidden DateTime Column date conversion babuman ASP.NET 2.0 Professional 0 February 1st, 2007 06:22 PM
Datatype mismatch on datetime column??? reidcor SQL Server DTS 3 May 9th, 2005 02:13 PM
Alter Column - Default Value sasidhar79 SQL Server 2000 2 January 18th, 2005 07:30 AM
Alter Default on a Column Gert SQL Server 2000 4 November 28th, 2003 08:58 AM



All times are GMT -4. The time now is 10:00 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.