hello this is working fine for me but i think it can be more simple can anyone help me with this code for checking the time and date entered by user
function ckeck_date($sug_date, $sug_time)
{
if ($sug_date[0] == NULL)
{
return TRUE;
}
else
{
for ($i = 0; $i < count($sug_date); $i++)
{
if ($this->_totimestamp($sug_date[$i], $sug_time[$i]) < mktime(23, 59, 59, date('m'), date('d') - 1, date('Y')))
{
$x=false;
}
else $y=true;
}
}
if(isset($x))
{
return $x*$y;
}
else return true;
}
Try this, take your date and time
$str = '2012-06-15 11:12:23'; // OR '15-06-2012 11:12:23'
if ( strtotime( $str ) > time( ) ) {
// Your time is greater than current time
}
For date you can use:
With strtotime you can create int
from string and compare them if they are in the future (if you compare against now
)
$today = strtotime(date("Y-m-d")); // today's date
$userd = strtotime("2012-10-16"); // users input
if ($userd > $today){
$valid = "yes";
} else {
$valid = "no";
}
If I am right you can add the time to the input as well, but you need to check the php documentation on this for correct date-time format
shorter:
if (strtotime($userdate) > strtotime(date("Y-m-d"))){
$valid = "yes";
}