timmah1 Posted December 14, 2008 Share Posted December 14, 2008 I have three items that have different expiration dates Every one end at midnight Item 1 expires the day of purchase Item 2 expires in 7 days Item 3 expires in 30 days. My question is, would this be correct? $expDate1 = date("Y-m-d 24:00"); $expDate2 = date("Y-m-d 24:00", strtotime(date("Y-m-d 24:00"." +7 days")); $expDate3 = date("Y-m-d 24:00", strtotime(date("Y-m-d 24:00"." +30 days")); If not, could please help me write the correct code? Thanks in advance Link to comment https://forums.phpfreaks.com/topic/136956-solved-time-date/ Share on other sites More sharing options...
timmah1 Posted December 14, 2008 Author Share Posted December 14, 2008 I had it wrong It's this code $expDate1 = date("Y-m-d 24:00"); $expDate2 = date("Y-m-d 24:00", strtotime(date("Y-m-d 24:00")." + 7 days")); $expDate3 = date("Y-m-d 24:00", strtotime(date("Y-m-d 24:00")." + 30 days")); Right now, it echos out 2008-12-14 24:00 1969-12-31 24:00 1969-12-31 24:00 I need everyone to expire at midnight, and the second one add 7 days, and the third one, add 30 days Link to comment https://forums.phpfreaks.com/topic/136956-solved-time-date/#findComment-715283 Share on other sites More sharing options...
timmah1 Posted December 14, 2008 Author Share Posted December 14, 2008 ok, I got the dates correct by doing this $expDate1 = date("Y-m-d 24:00"); $expDate2 = date("Y-m-d 24:00", strtotime('+1 week')); $expDate3 = date("Y-m-d 24:00", strtotime('+30 days')); Is 24:00 correct for midnight? Link to comment https://forums.phpfreaks.com/topic/136956-solved-time-date/#findComment-715285 Share on other sites More sharing options...
Mchl Posted December 14, 2008 Share Posted December 14, 2008 Is 24:00 correct for midnight? Depends on what you're going to do with it next, but in general 0:00 of next day is used http://www.gnu.org/software/shishi/manual/html_node/Time-of-day-items.html#Time-of-day-items Link to comment https://forums.phpfreaks.com/topic/136956-solved-time-date/#findComment-715291 Share on other sites More sharing options...
timmah1 Posted December 14, 2008 Author Share Posted December 14, 2008 Thanks mchl I have it working now, But now I have another problem I pull the correct expiration date, and put it into a hidden value <?php $sql9 = "SELECT * FROM stopDates WHERE sport = '$a[sport]'"; $q9 = mysql_query($sql9); $a9= mysql_fetch_assoc($q9); $expDate1 = date("Y-m-d 23:59:59"); $expDate2 = date("Y-m-d 23:59:59", strtotime('+1 week')); $expDate3 = date("Y-m-d 23:59:59", strtotime('+30 days')); $expDate4 = date("Y-m-d 23:59:59", strtotime($a9['season'])); $expDate5 = date("Y-m-d 23:59:59", strtotime($a9['playoffs'])); $expDate6 = date("Y-m-d 23:59:59", strtotime($a9['special'])); if($a['id'] == "1"){ $expDate = $expDate1; } elseif($a['id'] == "2"){ $expDate = $expDate2; } elseif($a['id'] == "3"){ $expDate = $expDate3; } elseif($a['id'] == "4"){ $expDate = $expDate4; } elseif($a['id'] == "5"){ $expDate = $expDate5; } elseif($a['id'] == "6"){ $expDate = $expDate6; } ?> <input name="exp" type="text" id="exp" value="<?=$expDate;?>" /> I try to echo the value on the next page with both of these $_SESSION['SESS_DATE'] = $_POST['exp']; <td><?=$_SESSION['SESS_EXP'];?></td> <td><?=$_POST['exp'];?></td> But no matter what, it shows today's date Any idea why? Link to comment https://forums.phpfreaks.com/topic/136956-solved-time-date/#findComment-715317 Share on other sites More sharing options...
Mchl Posted December 14, 2008 Share Posted December 14, 2008 echo $a['id']; before ifs to see what's the actual value. BTW: Short tags are evil. Link to comment https://forums.phpfreaks.com/topic/136956-solved-time-date/#findComment-715318 Share on other sites More sharing options...
timmah1 Posted December 14, 2008 Author Share Posted December 14, 2008 I've done that, and the correct ID's are present Link to comment https://forums.phpfreaks.com/topic/136956-solved-time-date/#findComment-715319 Share on other sites More sharing options...
timmah1 Posted December 14, 2008 Author Share Posted December 14, 2008 The id's echo out where they are suppose too, but the post only echo's out number 6 Any idea why? <?php $sql9 = "SELECT * FROM stopDates WHERE sport = 'nba'"; $q9 = mysql_query($sql9); while($a9= mysql_fetch_assoc($q9)) { echo $packID; if($packID == "1"){ $exp = date("Y-m-d 23:59:59"); ?><input name="exp" type="hidden" id="exp" value="<?=$exp;?>" /> <?php } elseif($packID == "2"){ $exp = date("Y-m-d 23:59:59", strtotime('+1 week')); ?><input name="exp" type="hidden" id="exp" value="<?=$exp;?>" /> <?php } elseif($packID == "3"){ $exp = date("Y-m-d 23:59:59", strtotime('+30 days')); ?><input name="exp" type="hidden" id="exp" value="<?=$exp;?>" /> <?php } if($packID == "4"){ $exp = date("Y-m-d 23:59:59", strtotime($a9['season'])); ?><input name="exp" type="hidden" id="exp" value="<?=$exp;?>" /> <?php } elseif($packID == "5"){ $exp = date("Y-m-d 23:59:59", strtotime($a9['playoffs'])); ?><input name="exp" type="hidden" id="exp" value="<?=$exp;?>" /> <?php } elseif($packID == "6"){ $exp = date("Y-m-d 23:59:59", strtotime($a9['special'])); ?><input name="exp" type="hidden" id="exp" value="<?=$exp;?>" /> <?php } } ?> Link to comment https://forums.phpfreaks.com/topic/136956-solved-time-date/#findComment-715346 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.