Forum Moderators: coopster
$today = date("F-j-Y, g:i:a");
echo $today;
but what if i wish to compare this with dates I have stored in a variable? i am using..
$date_to_compar = date("F-j-Y, g:i:a", mktime($hour, $minute, $ampm, $month, $day, $year));
if($today > $date_to_compar)
but $date_to_campar will not work. What must I change that to?
thanks again
$today = time();
echo $today; $date_to_compar = mktime($hour, $minute, $ampm, $month, $day, $year);
if($today > $date_to_compar) then convert...
disclaimer: my code above is untested off the top of my head and may contain errors, but should give you the basic idea. ;)
baze
the values are first obtained from a form
$day=$_REQUEST['day']; //read as integer ie 28
$month=$_REQUEST['month']; //read as name ie February
$year=$_REQUEST['year']; //read as full year ie 2005
$hour=$_REQUEST['hour']; //read as 1 - 12 ie 1
$minute=$_REQUEST['minute']; read as 1-60 ie 15
$ampm=$_REQUEST['ampm']; read as am/pm ie am
i then set todays date and obtain the date from the form..
$today = date("F-j-Y, g:i:a");
$date_to_compar = date("F-j-Y, g:i:a", mktime($hour, $minute, $ampm, $month, $day, $year));
I then wish to validate it..
if($today > $date_to_compar)
{
echo $date_to_compar;
echo $today;
die('Error, date has passed! <a href="javascript:history.go(-1)">back</a>');
}
I can do it for date no probs but i want it to check if the date and time has passed. Any ideas? thanks so far
$day='8';
$month='February';
$year='2005';
$hour= '1';
$minute='15';
$ampm='am'; $datestr = sprintf("%s %s, %s %s:%s%s",$month,$day,$year,$hour,$minute,$ampm);
$mytimestamp = strtotime($datestr);
$today = time();
echo "variable date: " . date("F-j-Y, g:i:a",$mytimestamp);
echo "<br>today date: " . date("F-j-Y, g:i:a",$today);
if ($today < $mytimestamp){
echo "<br>after today";
} else {
echo "<br>today is later";
}
Just remember the date() function returns strings not numbers or dates.
baze