hi i have the following error in my sent message file

Warning: date_diff() expects at least 2 parameters, 1 given in /home/letsswin/public_html/sent_mail.php on line 146
Show

Heres code section for error

<?php 
            $lastlog    = mysql_fetch_array(mysql_query(" select * from user_lastlogin  where online_status = '1' and user_id = '".$user_id."' "));
            $start_date = $lastlog['lastlogin']; 

            $online_status = $lastlog['online_status']; 
            ?>
            <?php if($online_status == '1') { echo date_diff($start_date); } ?>

I have previously add a similar error to this on a differrent file and tried adding that solution and it didnt work which was

$then = new DateTime($lastlogin['lastlogin']);
$now = new DateTime("now");
echo $then->diff($now)->format('%a days');

any ideas please would be much appreicated

The date_diff() function requires two arguments, also both must be resources of the DateTimeInterface, if you pass a string, as in your example, the function will fail.

So, you must write:

<?php

    $date_a = '2015-04-01';
    $date_b = '2015-03-25';

    $dt_a = new Datetime($date_a);
    $dt_b = new Datetime($date_b);

    $interval = date_diff($dt_a, $dt_b);
    echo $interval->format('%R%a days'); # -7 days

Or use the object style, like your previous example. Note that the result is an object that cannot be converted directly to a string, so you must use the format() method.

Ty very much solved x

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.