mysql插入当前日期+更多天

时间:2015-07-19 03:35:04

标签: php mysql date

嗨,我有这个问题,我已尝试使用DATE_ADD找到的所有解决方案,并且更像这样的。所以这是我的代码..

$create_time = date("Y-m-d H:i:s");
if (md5($_POST['norobot']) == $_SESSION['randomnr2'])   
{ 
    if ((strlen($usern) >= 5) && (strlen($pass) >= 5)&&(strlen($email) >= 12)&&(strlen($idcard)==7))
    {
        $usr = mysql_query("Select * from account.account where login='$usern'");
        $ema = mysql_query("Select * from account.account where email='$email'");

        if ((mysql_num_rows($usr)==1)|| (mysql_num_rows($ema)==1))
        {
            echo error("Cont sau email utilizate.Incercati altele sau click <a href='index.php?page=recuperare-pw'>aici</a> pentru recuperare parola.");
        }
        else
        {   
            if ($_POST['read'] == "checked")
            {
                $rand = rand(99999,9999999999);
                $cod_activ = md5($rand);
                //$cod_activ= "1";
                mysql_query("Insert into account.account (Login,Password,Real_name,Social_id,Email,status,create_time,gold_expire,silver_expire,safebox_expire,autoloot_expire,fish_mind_expire,marriage_fast_expire,money_drop_rate_expire,coins,web_aktiviert) values('$usern',password('$pass'),'$name','$idcard','$email','OK','$create_time','2022-12-31 12:00:00','2022-12-31 12:00:00','2022-12-31 12:00:00','2022-12-31 12:00:00','2022-12-31 12:00:00','2022-12-31 12:00:00','2022-12-31 12:00:00','0','$cod_activ')") or die(mysql_error());
                echo succes('Cont creat cu succes.Va puteti loga acum!');

而不是2022-12-31 12:00:00我想添加当前日期+ 30天任何帮助吗?我没有想法。

1 个答案:

答案 0 :(得分:0)

MySQL DATE_ADD可行。

SELECT DATE_ADD(CURDATE(),INTERVAL 30 DAY)

您的查询将是:

mysql_query("Insert into account.account (Login,Password,Real_name,Social_id,Email,status,create_time,gold_expire,silver_expire,safebox_expire,autoloot_expire,fish_mind_expire,marriage_fast_expire,money_drop_rate_expire,coins,web_aktiviert) values('$usern',password('$pass'),'$name','$idcard','$email','OK','$create_time',DATE_ADD(CURDATE(),INTERVAL 30 DAY),DATE_ADD(CURDATE(),INTERVAL 30 DAY),DATE_ADD(CURDATE(),INTERVAL 30 DAY),DATE_ADD(CURDATE(),INTERVAL 30 DAY),DATE_ADD(CURDATE(),INTERVAL 30 DAY),DATE_ADD(CURDATE(),INTERVAL 30 DAY),DATE_ADD(CURDATE(),INTERVAL 30 DAY),'0','$cod_activ')") or die(mysql_error());

注意:mysql_*函数已弃用,将在以后的版本中删除,请改用mysqliPDO

<强>更新

如果您需要日期时间,请使用CURRENT_TiMESTAMP代替CURDATE()

SELECT DATE_ADD(CURRENT_TIMESTAMP,INTERVAL 30 DAY)