troubleshooting Question

How to get CURRENT_TIMESTAMP or NOW in TIMESTAMP or DATETIME column

Avatar of sillygoose
sillygoose asked on
MySQL Server
6 Comments1 Solution1211 ViewsLast Modified:
Hi,

I have read everywhere for this.  Some say it can be done and some say it cannot.  I have 2 TIMESTAMP columns, idstart & idfinish.  In the start I want it to take the current time.  I have tried changing it to CURRENT_TIMESTAMP DEFAULT or ON UPDATE with not success.  I have also tried changing inside my php/html form to use different timestamp things/CURRENT_TIMESTAMP etc.
MySQL says it can be done: http://dev.mysql.com/doc/refman/5.0/en/timestamp-4-1.html

If you know the syntax please let me know cuz I'm doing it on the GUI in MySQL Administrator on Windows, I need to konw how to update an exiting DB/table like:

ALTER TABLE `onr`.`runs` MODIFY COLUMN `idstart` TIMESTAMP NOT NULL DEFAULT 'CURRENT_TIMESTAMP';

--this returns: "MYSQL error number 1067, invalid default value for idstart"

or just make it so somehow, from my form, the current time gets put in that column when some checkbox is checked, like:

<LABEL for="idstart">Start Time: </LABEL>
<INPUT type="text" name="idstart"> [YYYY-MM-DD HH:MM:SS]
<input type="checkbox" name="startcheck"> use current time
...
<?php
  if ($_POST['submit']) {
    if ($_POST['startcheck'] == "y") {
        $thetime = 'CURRENT_TIMESTAMP';
    }
    else {
        $thetime = $_POST['idstart'];
    }
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 6 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros