Today, We want to share with you PHP Time Ago Function Converting Timestamp.In this post we will show you php facebook time ago function, hear for convert timestamp to time ago php we will give you demo and example for implement.In this post, we will learn about converting timestamp to time ago in php with an example.
PHP Time Ago Function Converting Timestamp
Contents
There are the Following The simple About PHP Time Ago Function Converting Timestamp Full Information With Example and source code.
As I will cover this Post with live Working example to develop php time ago like facebook, so the Converting timestamp to time ago in PHP e.g Today, Yesterday, 1 day ago, 2 days ago for this example is following below.
Time ago implementation in PHP
converting timestamp to time ago in php
index.php
<?php //YYYY-MM-DD H:M:S $post_date = "2020-06-14 11:22:20"; $time_ago=get_timeago(strtotime($post_date)); //$time_ago=get_timeago(strtotime($row['post_date'])); echo $time_ago; function get_timeago( $post_time ) { $real_estimate_time = time() - $post_time; if( $real_estimate_time < 1 ) { return 'Your Time less than 1 second ago'; } $all_time_date_condition = array( 12 * 30 * 24 * 60 * 60 => 'year', 30 * 24 * 60 * 60 => 'month', 24 * 60 * 60 => 'day', 60 * 60 => 'hour', 60 => 'minute', 1 => 'second' ); foreach( $all_time_date_condition as $get_secs => $live_str ) { $days = $real_estimate_time / $get_secs; if( $days >= 1 ) { $results = round( $days ); return 'about ' . $results . ' ' . $live_str . ( $results > 1 ? 's' : '' ) . ' ago'; } } } ?>
Web Programming Tutorials Example with Demo
Read :
Summary
You can also read about AngularJS, ASP.NET, VueJs, PHP.
I hope you get an idea about PHP Time Ago Function Converting Timestamp.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, donβt forget to share.
I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I’m a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.