about date

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bugthefixer
Forum Contributor
Posts: 118
Joined: Mon Mar 22, 2004 2:35 am

about date

Post by bugthefixer »

my prog compare two times input by user in a format 00:00:00 and its 24 hrs format...right now it only check whether 20:00:00 is before 21:00:00 but now i want to make it such a way that it can also tell me that 20:00:00 of first day is before 19:00:00 of second day...my present code is

Code: Select all

<?phpfunction compareTime($str) {
	$day=1;
	$arr=split(":",$str);
	global $time;
	if(isset($time))
		{
		$prev_time=$time;
		$time=mktime($arr[0],$arr[1],$arr[2],1,$day);
		if($time<$prev_time)
			return 1;
		}
	else {
		$time=mktime($arr[0],$arr[1],$arr[2],1,$day);
		return 1;
		}	
	}


?>
in other words i need some way to increment $day so that it can handle days as well..
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

You could use your time values in mktime() which will return the number of seconds in the date so you can easily compair them.
Post Reply