duansen6750 2018-03-28 18:23
浏览 44

重力形式将日期转换为Unix并添加一年

I'm trying to convert a date in WordPress Gravity Forms from dmy to Unix, which works fine by adding the below to functions.php but I want to add a +1 year to the converted date. Where am I going wrong?

  function rkv_datesubmit_fix2 ($form){
        //ACTUAL START DATE FIELD, date field id is 601 in gravity forms
        $raw_srt = $_POST['input_601'];
        $raw_end = $_POST['input_602'];

        // convert dates to unix
        $fix_srt = strtotime ($raw_srt);
        $fix_end = strtotime($raw_end);

            //output to gravity forms field 603 (start date)
            //output to gravity forms field 604 (end date)
        $_POST['input_603'] = $fix_srt;
        $_POST['input_604'] = $fix_end;
    }

add_action('gform_pre_submission', 'rkv_datesubmit_fix2');

If it change $fix_srt = strtotime ($raw_srt); to strtotime('+ 1 year', $raw_srt); I get 1971/1/1, not the original input date from Gravity field 601 plus a year.

  • 写回答

1条回答 默认 最新

  • dpbtbcz6650 2018-03-28 22:26
    关注

    Here is the working code:

    function rkv_datesubmit_fix2 ($form){
        //ACTUAL START DATE FIELD, date field id is 601 in gravity forms
        $raw_srt = $_POST['input_601'];
        $raw_end = $_POST['input_602'];
    
        // convert dates to unix
        $fix_srt = strtotime ($raw_srt);
        $fix_end = strtotime($raw_end.' + 1 year');
    
        //output to gravity forms field 603 (start date)
        //output to gravity forms field 604 (end date)
        $_POST['input_603'] = $fix_srt;
        $_POST['input_604'] = $fix_end;
    }
    
    add_action('gform_pre_submission', 'rkv_datesubmit_fix2');
    

    For adding +1 year to $fix_end we just used strtotime($raw_end.' + 1 year'). This is simplest way to achieve the result you want.

    评论

报告相同问题?

悬赏问题

  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?