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";
        $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 (31) Add New Comment
porn2024-06-19 11:08 AM

I like it when individuals come together and share thoughts. Great blog, keep it up!

usbzbz2024-06-19 7:49 AM

I was curious if you ever thought of changing the structure of your site? Its very well written; I love what youve got to say. But maybe you could a little more in the way of content so people could connect with it better. Youve got an awful lot of text for only having 1 or two pictures. Maybe you could space it out better?

DTWNdb2024-06-19 3:11 AM

What's Going down i'm new to this, I stumbled upon this I've discovered It absolutely useful and it has helped me out loads. I hope to give a contribution & assist other users like its helped me. Good job.

hd porn2024-06-17 9:08 AM

Hi there, I enjoy reading all of your article post. I like to write a little comment to support you.

Aliza2024-06-16 12:01 AM

Wonderful post! We will be linking to this great article on our site. Keep up the good writing.

hd porn2024-06-15 6:16 AM

Way cool! Some very valid points! I appreciate you penning this post and also the rest of the website is also really good.

amazon review2024-06-15 5:44 AM

you're in reality a just right webmaster. The website loading speed is amazing. It seems that you're doing any unique trick. In addition, The contents are masterpiece. you have performed a excellent job in this matter!

spine calculator2024-06-15 1:13 AM

You made some really good points there. I looked on the net for more information about the issue and found most people will go along with your views on this site.

Freeman2024-06-14 5:45 PM

Good day! I know this is kind of off topic but I was wondering which blog platform are you using for this site? I'm getting fed up of Wordpress because I've had problems with hackers and I'm looking at alternatives for another platform. I would be awesome if you could point me in the direction of a good platform.

Miriam2024-06-14 4:40 PM

Hello there! This blog post could not be written any better! Going through this article reminds me of my previous roommate! He continually kept preaching about this. I'll send this article to him. Fairly certain he'll have a great read. Many thanks for sharing!

uxvkkl2024-06-14 2:07 PM

Thanks for the auspicious writeup. It in truth was a leisure account it. Glance complicated to far added agreeable from you! However, how can we communicate?

Swiftnook.top2024-06-14 2:04 AM

Make Your Website Stand Outside The Crowd Swiftnook - Swiftnook.top,

rendingnicheblog.top2024-06-13 7:05 PM

Top 10 Online Poker Player Blog List rendingnicheblog (rendingnicheblog.top)

Alta2024-06-13 2:59 PM

Hmm it seems like your blog ate my first comment (it was extremely long) so I guess I'll just sum it up what I wrote and say, I'm thoroughly enjoying your blog. I as well am an aspiring blog blogger but I'm still new to everything. Do you have any tips and hints for beginner blog writers? I'd genuinely appreciate it.

Mauricio2024-06-13 9:47 AM

Your way of describing the whole thing in this article is really pleasant, all be able to easily know it, Thanks a lot.

reletis nerev usunob emened2024-06-12 4:16 PM

Because the admin of this site is working, no uncertainty very quickly it will be famous, due to its quality contents.

porn2024-06-12 4:13 PM

Pretty portion of content. I just stumbled upon your site and in accession capital to say that I get in fact enjoyed account your blog posts. Any way I'll be subscribing in your feeds and even I success you access consistently quickly.

fNrZGN2024-06-12 3:09 PM

Very good blog post. I certainly love this website. Thanks!

Isaac2024-06-12 8:09 AM

Thanks for the auspicious writeup. It in reality was a enjoyment account it. Look complicated to more brought agreeable from you! By the way, how can we be in contact?

XRCyaZ2024-06-11 6:42 PM

It is the best time to make some plans for the long run and it's time to be happy. I have learn this put up and if I could I wish to counsel you some attention-grabbing issues or suggestions. Perhaps you could write subsequent articles regarding this article. I wish to read even more things approximately it!

reletis nerev usunob emened2024-06-11 4:17 PM

What's up to all, for the reason that I am actually eager of reading this blog's post to be updated daily. It includes nice information.

Edwardo2024-06-11 2:17 PM

Hello everybody, here every person is sharing these knowledge, so it's pleasant to read this webpage, and I used to pay a visit this blog daily.

Frankie2024-06-11 6:45 AM

Thanks for another informative site. The place else may I am getting that kind of information written in such an ideal means? I have a challenge that I am simply now working on, and I've been on the look out for such info.

best porn movies - budsal.com2024-06-10 2:49 PM

Hmm it seems like your blog ate my first comment (it was extremely long) so I guess I'll just sum it up what I submitted and say, I'm thoroughly enjoying your blog. I too am an aspiring blog blogger but I'm still new to the whole thing. Do you have any recommendations for rookie blog writers? I'd genuinely appreciate it.

usunob emened2024-06-10 2:41 PM

Wonderful blog! Do you have any recommendations for aspiring writers? I'm hoping to start my own blog soon but I'm a little lost on everything. Would you propose starting with a free platform like Wordpress or go for a paid option? There are so many options out there that I'm totally overwhelmed .. Any suggestions? Thank you!

Blog2024-06-09 5:38 AM

Work From My Home Tips - Blogging For Online Income Blog

grfHct2024-06-09 2:55 AM

Thanks to my father who told me on the topic of this blog, this web site is really remarkable.

YdvCXv2024-06-09 2:11 AM

Pretty component of content. I just stumbled upon your website and in accession capital to claim that I acquire actually loved account your blog posts. Anyway I'll be subscribing for your feeds and even I success you get right of entry to consistently quickly.

Hokicoy Alternatif2024-04-30 9:59 PM

Keep on working, great job!

Aayush Shrestha2024-03-07 7:23 AM

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

Yoho Cloud2023-05-09 7:10 AM

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