How to check if the user has not login for a particular number of days

How would you check to see if the user has not login for more than 2 weeks? I have a table collumn called session and stored the date when the user registered but can’t figure out how to check it in a query to see if they have not login for a particular number of days

is the date column type timestamp or anything related to time?( like it’s not integer or string like xxxx,xx,xx)

if it is. then you can use this. although i don’t know your codes :grinning:
let me find more

$now = time(); // or your date as well
$your_date = $row['user_login_date'];/*strtotime("2010-01-31")*/
$datediff = $now - $your_date;

ah… so you do have to subtract the different in time

like subtract user login date from another date (instead of current date)?

confused

then how would I use $datediff? would i use it in my squery?

how would you convert hours to seconds? I know that to convert mins to seconds = 15mins X 60 but to convert hours? how would you convert 4 hours into seconds? 46060? sounds too much

maybe?:

hours_to_seconds(date("h"));
function hours_to_seconds($hour){
$convert= $hour * 60 * 60;
return $convert;
}

My function works best:

function hoursToSeconds($hour = date("H")) {
$convertedValue = $hour * (60 * 60);
return $convertedValue;
}
1 Like

so how it’ll work for function inputs? i get this error :eyes::

Fatal error: Constant expression contains invalid operations in /wwwoKXR48 on line 7

I will correct the code straight away:

function hoursToSeconds($hour = date("H")){
$convertedValue = $hour * 3600; // did 60 * 60 before
return $convertedValue;
}
1 Like

not again :c
i got same error too

line seven is where function declares not convertion :grinning:

Then:

function hoursToSeconds ($hour) {
$convertedValue = $hour * 3600;
return $convertedValue;
}

We should then define $hour as a integer (e.g. 4) and use that function.

Maybe DateInterval would help? Or better yet, use Carbon, which is an even easier way to do date and time things in PHP.

2 Likes