0

I need to make a Registration show hide based on whether you are > 48 hours or =< 48 hours out...

I wrote this before based on a start and end time...

<?php
	$startdate = $row_product['startdate'];
	$enddate = $row_product['enddate']; 
	$todays_date = date("Y-m-d");
	
    if ($enddate <= $todays_date) { 
		header('Location: expired.php');
	}
	else{
	}
	
	if ($startdate > $todays_date){
		header('Location: notyet.php');
	}
	else {
	}
?>

Can I do math in the $enddate like $row_product - 48:00:00; or something?

OR, should I add a row to the table that is LastAvailable and compare the 2 rows? Start and lastavailable???

Am I on the right track?

Ted

2
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by changeco
0

So I can write something as easy as this?

SELECT *
FROM `ClassDetails`
WHERE CURDATE( ) > `CDDate` AND CURDATE() < `CDLastTime`

Except I'm not sure about that last part... Would I need to put both math equations inside the CURDATE() brackets?

0

I realized I'm setting the date as a VARCHAR and not as a UNIX TIMESTAMP... Should I make the row UNIX then do the math then extract the correct format?

Or, can I do the math using mm/dd/yyyy?

0

I'm not sure what you mean.
If you want to know if a point in time has passed for a certain time span use something like

SELECT * from mytable where TIMEDIFF(startdate,NOW()) > '48:00:00'

That's what I meant by doing the math in the database, not in PHP.
And yes, of course, your time fields should be of type TIME or DATETIME, respectively.

Edited by smantscheff: n/a

0

thanks for the coaching @smantscheff - I truly appreciate it...

I changed the row to a UNIX DATETIME and the following code worked perfectly...

SELECT * FROM ClassDetails WHERE NOW() > `CDLastTime`

Thanks!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.