php date function, how to calculate how many days user are in website?
i’m stuck with php programming..
I need calculate how many days user have been in site. (Flat file website)
Registered since: <?php echo "$info[4]"; ?><br />
It prints out this : 03 Jan 2007 08:22 am
[ date("d M Y h:i a"); ]
So how can i calculate how mani days user are in website?
I have tried this, but it’s wrong.
<?php $bDay = mktime($info[4]);
$cTime = time();
$vecums = $cTime-$bDay;
$day = floor($vecums/(60*60*24));
echo " $day days<br />";?>
Here’s a complete solution:
http://www.addedbytes.com/php/php-datediff-function/
I always wondered why PHP doesn’t have an actual DateDiff function…
Here’s a complete solution:
http://www.addedbytes.com/php/php-datediff-function/
I always wondered why PHP doesn’t have an actual DateDiff function…
References :
First of all, I prefer to handle dates in Unix Timestamp format, its much easier to do it.
OPTION 1 : If you get the date from mysql, you can use the function UNIX_TIMESTAMP, it returns the timestamp format, then you can easy make the difference and divide it by (60*60*24).
OPTION 2 : I like twisted things, then you can correct that little code.
The syntax is as follows:
mktime ($hours,$minutes,$seconds,$month,$day,$year)
I dont think is necessary, I think you got that $info[4] from a MYSQL query, so I think the first option is just fine
References :