Jump to content

Simple Date/Time Check for a Form


jthurstenson

Recommended Posts

I am working on a simple form to be used on our intranet site. The purpose is to request/reserve a vehicle from our automotive dept.

 

I need to check the "DateNeeded" variable agains the "ReturnDate" variable to make sure DateNeeded is before ReturnDate, and return an error if it is not.

 

Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/127402-simple-datetime-check-for-a-form/
Share on other sites

I don't have the full code, but what you should do.

 

convert the returndate into a unix timestamp with http://nl2.php.net/maketime

do the same for dateneeded and compare the two.

 

This will allow you to also work with hours of you want to.

function is_due($date_needed, $date_return)
{
$needed = explode('/', $date_needed);
$return = explode('/', $date_return);

$DateNeeded = mktime(0, 0, 0, $needed[0], $needed[1], $needed[2]);
$ReturnDate = mktime(0, 0, 0, $return[0], $return[1], $return[2]);

if($DateNeeded < $ReturnDate)
	return true;

return false;
}

// Example usage:
if(is_due('10/7/2008', '10/6/2008'))
echo 'due';
else
echo 'not due';

Need help, ask :)

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.