?
Solved

MySQL, phpMyAdmin set default date to NOW()

Posted on 2009-04-20
6
Medium Priority
?
5,936 Views
Last Modified: 2013-12-12
phpMyAdmin - 2.11.8.1

How can I set the default for a DATE field to NOW()
0
Comment
Question by:Hube02
6 Comments
 
LVL 5

Accepted Solution

by:
AtanAsfaloth earned 2000 total points
ID: 24183850
Some google-ing suggests this is not possible. Instead, use a TIMESTAMP field and set its default value to CURRENT_TIMESTAMP.

http://dev.mysql.com/doc/refman/5.0/en/timestamp.html
0
 
LVL 10

Expert Comment

by:mahome
ID: 24183904
As AtanAsfaloth said only Timestamp is possible. Here is the page which describes which default values are possible:
http://dev.mysql.com/doc/refman/5.0/en/data-type-defaults.html
0
 
LVL 18

Author Comment

by:Hube02
ID: 24183989
Well, I found the same information, just hoping that I missed something. Since I do not wish to change the field type to TIMESTAMP I guess the answer is "I can't". Thanks anyway.
0
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
LVL 14

Expert Comment

by:shobinsun
ID: 24184033
Hi,

Use the field type as 'TIMESTAMP' and attribute:'ON UPDATE CURRENT_TIMESTAMP' and  default: 'CURRENT_TIMESTAMP'.


For more :

http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html

Regards.
0
 
LVL 10

Expert Comment

by:mahome
ID: 24184201
If you want to stay with DATE you can use a trigger, that sets your default value. That's not the same, but should work for you.
0
 
LVL 18

Author Comment

by:Hube02
ID: 24185528
Thanks for the info, but for this application it's just easier for me to add the NOW() function and the field name into the query that php sends. I was just hoping to eliminate that step from my php. To be honest, I find the fact that you cannot set a default value of a DATE or DATETIME field to the current date/time to be illogical.
0

Featured Post

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to implement server side field validation and display customized error messages to the client.
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month17 days, 6 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question