Page 1 of 1

mktime needs long is string

Posted: Wed Mar 31, 2010 1:11 am
by m2babaey
Hello
I am using mktime in my code and get this warning:

Warning: mktime() expects parameter 1 to be long, string given in (file_address.php) on line 329

This is the code:

Code: Select all

		$tmpDate = date('Y-m-d H:m:s');
		$query="SELECT * FROM res_restaurents WHERE user_id='".$_SESSION['userId']."' order by iD desc";
		$q=mysql_query($query);
		while($row_list = mysql_fetch_array($q))
		{
			$insertime=$row_list['dateCreated'];
		}		
		$date1 = time();
		$dat = explode(" ",$insertime);
		$tmpDate = explode("-", $dat[0]);
		$tmpTime = explode(":", $dat[1]);
		//echo "jj".$tmpTime[0]."jj";
		$date2 = mktime($tmpTime[0],$tmpTime[1],$tmpTime[2],$tmpDate[1],$tmpDate[2],$tmpDate[0]);
		$dateDiff = $date1 - $date2;
		$fullMinutes = floor(($dateDiff-($fullDays*60*60*24)-($fullHours*60*60))/60);
		$query = "SELECT minutes FROM user_register WHERE id='$user_id'";
			$q2=mysql_query($query) or die(mysql_error());
    $minutes=mysql_fetch_array($q2);
How can I fix it?
Thanks for your help

Re: mktime needs long is string

Posted: Wed Mar 31, 2010 2:10 am
by cpetercarter
Why are you using this complicated method to get a Unix timestamp from a MySQL date/time? I think you could use:

Code: Select all

$date2 = strtotime($insertime);

Re: mktime needs long is string

Posted: Wed Mar 31, 2010 2:10 am
by Benjamin
What is the value of $tmpTime[0]?
The Manual wrote:int mktime ([ int $hour = date("H") [, int $minute = date("i") [, int $second = date("s") [, int $month = date("n") [, int $day = date("j") [, int $year = date("Y") [, int $is_dst = -1 ]]]]]]] )