Jump to content

[SOLVED] Time & Date


timmah1

Recommended Posts

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.