[英]php incremente a date of x days / concatenation / management of days off and weekend
I'm trying to do a simply addition, Just in order to display some dates so Acutaly 我试图做一个简单的加法,只是为了显示一些日期所以
I've done something like that: 我已经做了类似的事情:
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 is in the following line that does not display any mistake: Amm在下面的行中不会显示任何错误:
`date_action`='".date('Y-m-d',strtotime('+"'.$row['jour'].'" days'))."',
What I was trying is to display the date incremented of the number of days contained in the var $row['jour'], but Actualy it just display to me 1970-01-01, so I do not understand why, because all the var have a positive number in that var. 我试图显示的是var $ row ['jour']中包含的天数的递增日期,但是实际上它只是向我显示1970-01-01,所以我不明白为什么,因为所有var在该var中有一个正数。
Moreover I have one javascript function: 此外,我有一个JavaScript函数:
Like that: 像那样:
<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>
Actualy this function only incremente dates if a day is a sunday or a satturday, it depens of which is the parameter setting from the database on this line: 实际上,此功能仅在日期是星期天或星期六的情况下递增日期,而该日期取决于这行中数据库的参数设置:
<?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();
} ?>
Because sometimes some companies does work on satturday. 因为有时有些公司确实在星期六工作。
I would like to know how to apply this function on the new date, before it is insert to the database? 我想知道如何在将新功能插入数据库之前在新日期应用此功能?
Is there a way I can apply a javascript function to a none-object item in php? 有没有一种方法可以将javascript函数应用于php中的非对象项?
Receive all my utmost Respect. 得到我最大的尊重。
Kind regards. 亲切的问候。
SP. SP。
try this for the php part of the question: 试试这个问题的PHP部分:
`date_action` = '". date('Y-m-d', strtotime(date("Y-m-d"). "+".$row['jour']."days"))."'
Edit:
编辑:
`date_action` = '". date('Y-m-d', strtotime(date("Y-m-d"). "+".$row['jour']."days"))."'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.