PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, February 22, 2022

[FIXED] MySQL default current_timestamp + 1 year

 February 22, 2022     mysql, phpmyadmin     No comments   

Issue

I make a simple table with id and date with default value CURRENT_TIMESTAMP and i am curious how to set date CURRENT_TIMESTAMP + 1 year. For example if NOW() is 2018-01-23 13:57:22 i want as default value to be 2019-01-23 13:57:22. I can made this with trigger or with code before insert new line but is there other shortcut?

For example: How can i set as default value DATE_ADD(CURRENT_TIMESTAMP, INTERVAL 1 YEAR)

Same problem with this: https://bugs.mysql.com/bug.php?id=56835


Solution

It cant be manual.

The DEFAULT value clause in a data type specification indicates a default value for a column. With one exception, the default value must be a constant; it cannot be a function or an expression. This means, for example, that you cannot set the default for a date column to be the value of a function such as NOW() or CURRENT_DATE. The exception is that you can specify CURRENT_TIMESTAMP as the default for TIMESTAMP and DATETIME columns.

So the only way right now is with trigger or manually before insert new line in table.



Answered By - Paraskevas Ntsounos
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing