mktime needs long is string

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
m2babaey
Forum Contributor
Posts: 364
Joined: Sun May 20, 2007 9:26 am

mktime needs long is string

Post 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
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: mktime needs long is string

Post 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);
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: mktime needs long is string

Post 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 ]]]]]]] )
Post Reply