[PHP] Better timestamp explanation to the client

2005-09-08 Thread Ryan A
Hi,
In one of our tables we have these fields:

cust_no bigint(20),
cust_name varchar(30),
last_online datetime,

and in that members profile, if someone visits it, on the top of the page we
have this:

// connect to db, query for record and display it below
Last seen: ?php echo $last_online; ?

Any ideas on the simplest way to make it look like this:

Last seen: Less than a minute ago!

Last seen: 25 mins ago

Last seen:  2 hours 11 mins ago

Last seen: 1 (or 2 or 3) day/s ago

else{ echo $last_seen; }



I have seen this done on a few sites (Swedish sites actually, I can give you
the URLs if you need them)

I think it looks much better than:
Last seen : 2005-09-07 20:59:01


Thanks!
Ryan

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Better timestamp explanation to the client

2005-09-08 Thread Chris
I'd probably out how many minutes it's been, then format it using if 
statements.


$iMinues = (value from database);
if(1  $iMinutes) $sLastseen = 'Less than a minute ago!';
elseif(1 == $iMinutes) $sLastseen = '1 minute ago';
elseif(60  $iMinutes) $sLastseen = {$iMinutes} minutes ago;
elseif(120  $iMinutes) $sLastseen = '1 hour '.($iMinutes - 60).' 
minutes ago';

...

I don't think there is any real shortcut for doing this kind of thing, 
though I could be wrong.


Chris

Ryan A wrote:


Hi,
In one of our tables we have these fields:

cust_no bigint(20),
cust_name varchar(30),
last_online datetime,

and in that members profile, if someone visits it, on the top of the page we
have this:

// connect to db, query for record and display it below
Last seen: ?php echo $last_online; ?

Any ideas on the simplest way to make it look like this:

Last seen: Less than a minute ago!

Last seen: 25 mins ago

Last seen:  2 hours 11 mins ago

Last seen: 1 (or 2 or 3) day/s ago

else{ echo $last_seen; }



I have seen this done on a few sites (Swedish sites actually, I can give you
the URLs if you need them)

I think it looks much better than:
Last seen : 2005-09-07 20:59:01


Thanks!
Ryan

 



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Better timestamp explanation to the client

2005-09-08 Thread Jordan Miller
methinks you should convert the datetime to a unix timestamp with  
strtotime(). then you can compare the difference between this  
timestamp and a unix timestamp of now to find if you have logged in  
within a min. of the previous time. Then, once you know what text to  
display (e.g. Less than a minute ago!), you can format the original  
datetime timestamp with the date() function to be however you like.  
You may have to read the manuals for all three of these functions  
several times. good luck!


actually, you may be able to do simple operators (e.g. , , or -)  
with the datetime as is, without having to convert to a unix  
timestamp. NOW in datetime format can be gotten with:

$now = date('Y-m-d H:i:s');

i'm not sure though. just try it!

Jordan


On Sep 8, 2005, at 9:41 AM, Ryan A wrote:


Hi,
In one of our tables we have these fields:

cust_no bigint(20),
cust_name varchar(30),
last_online datetime,

and in that members profile, if someone visits it, on the top of  
the page we

have this:

// connect to db, query for record and display it below
Last seen: ?php echo $last_online; ?

Any ideas on the simplest way to make it look like this:

Last seen: Less than a minute ago!

Last seen: 25 mins ago

Last seen:  2 hours 11 mins ago

Last seen: 1 (or 2 or 3) day/s ago

else{ echo $last_seen; }



I have seen this done on a few sites (Swedish sites actually, I can  
give you

the URLs if you need them)

I think it looks much better than:
Last seen : 2005-09-07 20:59:01


Thanks!
Ryan

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php






--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php