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

Recommended Answers

All 6 Replies

thanks @smantscheff! that's exactly what I needed...

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?

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?

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.

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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.