mktime needs long is string

Discussion in 'PHP' started by promotingspace.net, Mar 30, 2010.

  1. #1
    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:
    		$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);
    PHP:
    How can I fix it?
    Thanks for your help
     
    promotingspace.net, Mar 30, 2010 IP
  2. Alex Roxon

    Alex Roxon Active Member

    Messages:
    424
    Likes Received:
    11
    Best Answers:
    7
    Trophy Points:
    80
    #2
    Just above, try something like this:

    $tmpTime = array_map("floatval", $tmpTime);
    $tmpDate = array_map("floatval", $tmpDate);
    PHP:
    If that doesn't work you might want to use var_dump to see exactly what data is stored in the array.
     
    Alex Roxon, Mar 31, 2010 IP
  3. stephan2307

    stephan2307 Well-Known Member

    Messages:
    1,277
    Likes Received:
    33
    Best Answers:
    7
    Trophy Points:
    150
    #3
    There is a nice function called strtotime which I would use here.

    try something like this
    
    $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();
    
    
            $date2 = strtotime($insertime);
          
          
            $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);
    
    PHP:
     
    stephan2307, Mar 31, 2010 IP