Reputation: 2694
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:
`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.
Moreover I have one javascript function:
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?
Receive all my utmost Respect.
Kind regards.
SP.
Upvotes: 0
Views: 159
Reputation: 5239
try this for the php part of the question:
`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"))."'
Upvotes: 1