Choose Color

  • +234-81022-60007
  • contact@braintechitconsult.com
  • Opening: 09:00am - 5:00pm
#

Call Now(+234) 8105 1640 38

Send Messagecontact@braintechitconsult.com

Our LocationSuit A17 Shoku Plaza, Offa Kwara State.

  • Home
  • About Us
  • Our Services
    • Our Services
    • Project Design
  • Courses
  • Login
  • Tutorials
  • Contact
Apply

View Tutorial

  • Home
  • View Tutorial
#
By: Admin 08-05-2020 PHP
How to differenciate between date post and current time

The following Code will differenciate between date post and current time

<?php
date_default_timezone_set('Africa/Lagos');
function convert($datetime){
  $time=strtotime($datetime);
  $diff=time()-$time;
  $diff/=60;
  $var1=floor($diff);
  $var=$var1<=1 ? 'min' : 'mins';
  if($diff>=60){
    $diff/=60;
    $var1=floor($diff);
    $var=$var1<=1 ? 'hr' : 'hrs';
    if($diff>=24){$diff/=24;$var1=floor($diff);$var=$var1<=1 ? 'day' : 'days';
    if($diff>=30.4375){$diff/=30.4375;$var1=floor($diff);$var=$var1<=1 ? 'month' : 'months';
    if($diff>=12){$diff/=12;$var1=floor($diff);$var=$var1<=1 ? 'year' : 'years';}}}}
    echo $var1,' ',$var,' ago';
  }
  $date = date('Y-m-d H:i:s');
  echo $date; 
  echo "<br>";


$datetime="2020-04-27 12:00:00";
 echo convert($datetime);
 ?>

Leave a Reply

Your email address will not be published. Required fields are marked *

Categories

  • HTML16
  • CSS30
  • HTML & CSS80
  • JavaScript23
  • PHP28
  • Python16
  • jQuery30
  • C#80
  • C++80
  • V B .Net23
  • V B 6.028
  • SQL30
  • Bootstrap80
  • Node.js23
  • React.js28

Recent Posts

How to differenciate between date post and current time

08-05-2020

Recent Tags

  • PHP
  • Python
  • Javascript
  • V B .Net
  • C++
  • Boostrap
#

The organizations have been given out the necessary requirement Students needed pertaining to his/her choosing field

  • Phone: +234 8105164038
    Phone: +234 8102260007
  • Email: contact@braintechitconsult.com
  • Address: Suit A17 Shoku Plaza, Offa Kwara State.

Useful Links

  • Home
  • About Us
  • Courses
  • Login
  • Tutorial
  • Contact

Latest Tutorial

#

How to differenciate between...

08-05-2020

Subscribe News Feeds

Don't miss to subscribe to our news feed, Get the latest updates from us!

© Copyright 2012 - 2025 BrainTech IT Consult All Rights Reserved