Someone can help me making a script to:
1 - Add 5 hours and 10 minutes to actual date/time (that is the diference for my time and the time of the webserver),
2 - Calculate the diference between 2 dates last login and now,
3 - The final step put the diference time in a variable and echo "Your Last Login time was about 5 hours ago", "Your Last Login time was about 5 minutes ago" and "Your Last Login time was about 5 weeks ago"
My webserver is Windows
Thanks in advance
HELP in Timestamp Difference
Moderator: General Moderators
-
mcoelho123
- Forum Commoner
- Posts: 37
- Joined: Tue Jun 06, 2006 6:27 am
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Firstly, timestamps are simply seconds since epoch.. so to add a certain time to a timestamp simply add the equivilent in seconds...
1)
2) You should be able to figure out the second one, simply minus the previous timestamp from time()
3) I would probably throw the difference variable in an if/elseif to get the correct wording output.. something along the lines of
1)
Code: Select all
//add 5 hours and 10 minutes
$timestamp += 18600;2) You should be able to figure out the second one, simply minus the previous timestamp from time()
3) I would probably throw the difference variable in an if/elseif to get the correct wording output.. something along the lines of
Code: Select all
if ($difference < 60)
{
$since = $difference;
$period = 'seconds';
}
elseif ($difference < 3600)
{
$since = ceil($difference / 60);
$period = 'minutes';
}
elseif ($difference < 86400)
{
$since = ceil($difference / 3600);
$period = 'hours';
}
else
{
$since = ceil($difference / 86400);
$period = 'days';
}
echo 'It has been '. $since .' '. $period .' since your last login';-
mcoelho123
- Forum Commoner
- Posts: 37
- Joined: Tue Jun 06, 2006 6:27 am