[英]php incremente a date of x days / concatenation / management of days off and weekend
我試圖做一個簡單的加法,只是為了顯示一些日期所以
我已經做了類似的事情:
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部分:
`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"))."'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.