Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > MySQL
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 8th, 2003, 05:41 AM
Friend of Wrox
 
Join Date: Jun 2003
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
 
Old September 12th, 2003, 01:22 AM
Registered User
 
Join Date: Sep 2003
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

 
Old September 12th, 2003, 01:33 PM
Friend of Wrox
 
Join Date: Jun 2003
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/
 
Old September 17th, 2003, 09:47 PM
Registered User
 
Join Date: Sep 2003
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.

 
Old September 18th, 2003, 01:04 AM
Friend of Wrox
 
Join Date: Jun 2003
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/
 
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.





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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.