doomm4711 2018-10-25 08:43
浏览 47

如何通过在php中手动添加天数来增加所选日期范围内的日期

Here my jquery ajax request,

I m trying to send selected date or manually increasing days values to the controller

function myFunction(selected_first_date){
    var   get_my_value = $('#get_my_value').val();
    $.ajax({
              url :"<?php echo base_url();?>index.php/holiday_package_controller/PackageController/dateChangerFunction",
              type:"POST",
              data:{
                 get_my_value:get_my_value,
                 selected_first_date:selected_first_date
              },
              dataType: "json",
              success: function(data){
               //$('#cash_receipt_voucher_date').html(data);
               console.log(data);
               $('#incremented_date').val(data.incremented_date);
              }
        });
}

Controller

$get_my_value = $this->input->post("get_my_value");

$selected_first_date = $this->input->post("selected_first_date");
if(!empty($selected_first_date)){
    for($i=0; $i<=$get_my_value; $i++)
        $repeat = strtotime("+$i day",strtotime($selected_first_date));

    $rdate = date('Y-m-d',$repeat);
    print_r($rdate);
    exit();
}
  • 写回答

2条回答 默认 最新

  • doutuo6689 2018-10-25 08:49
    关注

    I like the DateTime class for things like this https://3v4l.org/g9v53:

    <?php
    
    $date = new DateTime('2014-09-18 10:00:00');
    $date->modify('+12 hours');
    echo $date->format('Y-m-d H:i:s');
    

    2014-09-18 22:00:00

    Here are all the relative modification formats from the docs:

    https://secure.php.net/manual/en/datetime.formats.relative.php

    If the date time you are sending is not in 'Y-m-d H:i:s' format, then use DateTime::createFromFormat($customFormat, $dateTimeString);

    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么