2019-03-15 Pujan Niroula 1 Minute(s) Read

[How to] Create Time Ago in PHP

img-php time ago function thumbnail.jpg

 Hello there,
After a long time I am back with simple and little tricky but widely used code. If you want to create time ago system just like facebook. This is just a simple and tiny function which will convert PHP timestamp.

If you stored time with time() function in then this will be very easy just use the following function. Time() function returns the current time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT).

function get_time($t_time) {
    $pt = time() - $t_time;
    if ($pt>31536000)
        $p = date("Y-M-j",$t_time);
    elseif ($pt>=86400)
        $p = date("M-j",$t_time);
    elseif ($pt>=3600)
        $p = (floor($pt/3600))."h ago";
    elseif ($pt>=60)
        $p = (floor($pt/60))."m ago";
    elseif ($pt<2)
        $p="Just now";
    else
        $p = $pt."s ago";
    return $p;
};

If current time is greater than an year(31536000 seconds) then this will return full date  yy-mm-dd similarly if current time is less than an year  this will return just  mm-dd format furthermore it will return  hour, minute and second ago.

To call the function just type get_time(time()-100);

Thanks for reading :)

Tags:php, how to, time,
Comments (23) Add New Comment
child porn2024-09-15 1:09 AM

I've been surfing online more than 4 hours today, yet I never found any interesting article like yours. It's pretty worth enough for me. Personally, if all web owners and bloggers made good content as you did, the internet will be much more useful than ever before.

Reply
Roulette tournaments2024-09-14 11:46 PM

Have you ever thought about writing an e-book or guest authoring on other sites? I have a blog based upon on the same information you discuss and would really like to have you share some stories/information. I know my subscribers would value your work. If you are even remotely interested, feel free to shoot me an email.

Reply
ZEdess2024-09-14 8:42 PM

I pay a quick visit daily a few blogs and sites to read content, except this web site presents feature based posts.

Reply
bdg win2024-09-14 10:39 AM

Hello, i think that i saw you visited my website thus i came to “return the favor”.I'm trying to find things to enhance my web site!I suppose its ok to use some of your ideas!!

Reply
internet Casino2024-09-13 8:51 PM

Everything is very open with a clear description of the issues. It was truly informative. Your site is useful. Many thanks for sharing!

Reply
plus size kawaii clothing2024-09-13 7:51 PM

Yesterday, while I was at work, my sister stole my apple ipad and tested to see if it can survive a 25 foot drop, just so she can be a youtube sensation. My iPad is now destroyed and she has 83 views. I know this is completely off topic but I had to share it with someone!

Reply
slot payouts2024-09-12 2:18 PM

Hi there! This is my 1st comment here so I just wanted to give a quick shout out and say I really enjoy reading through your articles. Can you recommend any other blogs/websites/forums that cover the same subjects? Thanks!

Reply
buy viagra online2024-09-12 9:00 AM

I'm really enjoying the theme/design of your site. Do you ever run into any web browser compatibility problems? A small number of my blog visitors have complained about my site not working correctly in Explorer but looks great in Safari. Do you have any recommendations to help fix this issue?

Reply
child porn2024-09-11 9:51 PM

I'm not sure why but this site is loading extremely slow for me. Is anyone else having this issue or is it a problem on my end? I'll check back later and see if the problem still exists.

Reply
child porn2024-09-11 4:42 PM

You are so awesome! I do not suppose I've read something like this before. So wonderful to find somebody with some original thoughts on this subject matter. Really.. thank you for starting this up. This site is one thing that's needed on the internet, someone with a bit of originality!

Reply
bahis siteleri2024-09-10 3:36 PM

Remarkable! Its genuinely awesome post, I have got much clear idea on the topic of from this post.

Reply
Web Site2024-09-09 6:50 AM

Greetings from Florida! I'm bored to death at work so I decided to browse your site on my iphone during lunch break. I love the info you provide here and can't wait to take a look when I get home. I'm amazed at how quick your blog loaded on my phone .. I'm not even using WIFI, just 3G .. Anyways, awesome site!

Reply
Web Site2024-09-09 3:52 AM

I think the admin of this website is actually working hard for his web page, as here every material is quality based stuff.

Reply
portoni industriali2024-09-08 11:44 PM

Aw, this was an extremely nice post. Taking a few minutes and actual effort to make a superb article… but what can I say… I hesitate a whole lot and never seem to get anything done.

Reply
Web Site2024-09-08 10:11 PM

My spouse and I stumbled over here coming from a different page and thought I should check things out. I like what I see so i am just following you. Look forward to checking out your web page yet again.

Reply
Web Site2024-09-08 9:10 PM

Hi there to all, as I am truly eager of reading this web site's post to be updated regularly. It consists of fastidious stuff.

Reply
Teresita2024-09-05 1:39 PM

Hello my friend! I wish to say that this post is awesome, nice written and include approximately all significant infos. I'd like to peer extra posts like this .

Reply
child sex2024-09-05 6:03 AM

This is really interesting, You are a very skilled blogger. I have joined your rss feed and look forward to seeking more of your excellent post. Also, I've shared your site in my social networks!

Reply
from2024-09-04 10:18 PM

Wow, fantastic blog layout! How long have you been blogging for? you made blogging look easy. The overall look of your web site is fantastic, let alone the content!

Reply
pornolar2024-09-04 8:01 PM

You need to be a part of a contest for one of the greatest websites on the web. I am going to recommend this website!

Reply
Hokicoy Alternatif2024-04-30 9:59 PM

Keep on working, great job!

Reply
Aayush Shrestha2024-03-07 7:23 AM

Will obviously use this the next time ! Thanks for the information brother

Reply
Yoho Cloud2023-05-09 7:10 AM

It help us alots and thanks for sharing such master piece .

Reply