【问题标题】:php incremente a date of x days / concatenation / management of days off and weekendphp增加x天的日期/连接/管理休息日和周末
【发布时间】:2012-10-04 13:00:21
【问题描述】:

我正在尝试做一个简单的加法, 只是为了显示一些日期,所以很准确

我做过类似的事情:

 while($row = mysql_fetch_assoc($qry)): 

   echo  $req="INSERT INTO `agenda` SET
     `code_s`= '".$row['code_s']."',
     `titre` ='".$row['titre']."',
     `action` ='".$row['action']."',
     `libelle`='".$row['libelle']."',
      `date_action`='".date('Y-m-d',strtotime('+"'.$row['jour'].'" days'))."',
      `qualite`='".$da['qualite']."',
      `n_doss`='".mysql_real_escape_string($_GET['n_doss'])."',
      `code_client`='".$creance['code_client']."'<br>";
      endwhile;     };

Amm 在下面一行没有显示任何错误:

 `date_action`='".date('Y-m-d',strtotime('+"'.$row['jour'].'" days'))."',

我试图显示 var $row['jour'] 中包含的天数递增的日期,但实际上它只显示给我 1970-01-01,所以我不明白为什么,因为所有 var 在该 var 中都有一个正数。

此外,我还有一个 javascript 函数:

这样:

<script type="text/javascript">
    function getdate2() {
        var items = new Array();
        var itemCount = document.getElementsByClassName("datepicker hasDatepicker");

        for (var i = 0; i < itemCount.length; i++) {
            items[i] = document.getElementById("date" + (i + 1)).value;
        }



        for (var i = 0; i < itemCount.length; i++) {
            items[i] = document.getElementById("date" + (i + 1)).value;
            var itemDtParts = items[i].split("-");
            var itemDt = new Date(itemDtParts[2], itemDtParts[1] - 1, itemDtParts[0]);
        <?php $sql="SELECT * FROM `societe` WHERE `id`=1"; $result=mysql_query($sql) or die; $data=mysql_fetch_assoc($result);?><?php if($data['samedi']==0) {?>
            if (itemDt.getDay() == 6) {

                itemCount[i].value = (itemDt.getDate() < 9 ? "0" : "")+ (itemDt.getDate()+2)+ "-" + (itemDt.getMonth() < 9 ? "0" : "") + (itemDt.getMonth() + 1) + "-" + itemDt.getFullYear();


            }
            <?php } ?>
            if (itemDt.getDay() == 0) {

               itemCount[i].value = (itemDt.getDate() < 9 ? "0" : "")+ (itemDt.getDate()+1)+ "-" + (itemDt.getMonth() < 9 ? "0" : "") + (itemDt.getMonth() + 1) + "-" + itemDt.getFullYear();


            }

        }
       return items;
       }
</script>

实际上这个函数只在星期天或星期六时增加日期,它取决于这行数据库中的参数设置:

<?php $sql="SELECT * FROM `societe` WHERE `id`=1"; $result=mysql_query($sql) or die; $data=mysql_fetch_assoc($result);?><?php if($data['samedi']==0) {?>
                if (itemDt.getDay() == 6) {

                    itemCount[i].value = (itemDt.getDate() < 9 ? "0" : "")+ (itemDt.getDate()+2)+ "-" + (itemDt.getMonth() < 9 ? "0" : "") + (itemDt.getMonth() + 1) + "-" + itemDt.getFullYear();


                } ?>

因为有时有些公司会在星期六上班。

我想知道在新日期插入数据库之前如何应用这个函数?

有没有办法可以将 javascript 函数应用于 php 中的非对象项?

接受我最大的尊重。

亲切的问候。

SP。

【问题讨论】:

    标签: php javascript date increment weekend


    【解决方案1】:

    试试这个问题的 php 部分:

    `date_action` = '". date('Y-m-d', strtotime(date("Y-m-d"). "+".$row['jour']."days"))."'
    

    编辑:

     `date_action` = '". date('Y-m-d', strtotime(date("Y-m-d"). "+".$row['jour']."days"))."'  
    

    【讨论】:

    • ) 解析错误:语法错误,意外的 T_ENCAPSED_AND_WHITESPACE,需要 T_STRING 或 T_VARIABLE 或 T_NUM_STRING i
    • 好的感谢您的回答,它可以正常工作。您对如何应用 javascript 函数有任何想法吗?亲切的问候。 SP
    • np,试图理解您的 js 问题 :)...none-object in php 是什么意思?
    • 好的,让我猜猜,你想在数据库中插入itemCount[i].valueitems
    • 是的,先生,这是对的,输入中实际上没有对象
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多