0

I have a Mysql 5.5 and a table with a column as follow:

`VERSION_TS` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP

but i'm having difficulties lately i'm getting this exception:

Incorrect datetime value: '1998-03-20' for column 'VERSION_TS' at row 1

when trying to enter values to the table, values of type Date, using mySql MakeDate(). Now, i can't change the function that return Date, but i can change the column to Date, but then i'll lose the default value. i've tried a couple of things, and then checked the web, and from what i understand in Mysql 5.5 there is no way to do it, but i could be wrong, so i came here to ask:

  • Is there a way that i can change the column to a Date and still have a default value?
  • Also, is there a better way to do approach the problem?
2
  • can you tell in which language the code is written which returns Date. Commented Dec 3, 2014 at 12:17
  • @suchit it's written in MySql Commented Dec 3, 2014 at 12:40

2 Answers 2

1

I think the documentation is quite clear on this point:

TIMESTAMP and DATETIME columns can be automatically initialized and updated to the current date and time (that is, the current timestamp).

So, this does not apply to DATE. However, you could create a view that does what you want:

create view v_table as
    select t.*, date(version_ts) as version_date
    from table t;
Sign up to request clarification or add additional context in comments.

Comments

1

if the function which returns date is written in php then after receiving the date value you can do this:

  $date = new DateTime('2006-12-12');
            echo date_format($date,'Y-m-d H:i:s');// this you can store in mysql table. 

  if not same kind of approach you can apply in the respective language to do the job.

OR work with view as Gordon Linoff mentioned.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.