Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php datetime to timestamp

$time = '2021-03-31 23:59:00';
strtotime($time);
Comment

Converting timestamp to time ago in PHP

function time_elapsed_string($ptime)
{
    $etime = time() - $ptime;

    if ($etime < 1)
    {
        return '0 seconds';
    }

    $a = array( 365 * 24 * 60 * 60  =>  'year',
                 30 * 24 * 60 * 60  =>  'month',
                      24 * 60 * 60  =>  'day',
                           60 * 60  =>  'hour',
                                60  =>  'minute',
                                 1  =>  'second'
                );
    $a_plural = array( 'year'   => 'years',
                       'month'  => 'months',
                       'day'    => 'days',
                       'hour'   => 'hours',
                       'minute' => 'minutes',
                       'second' => 'seconds'
                );

    foreach ($a as $secs => $str)
    {
        $d = $etime / $secs;
        if ($d >= 1)
        {
            $r = round($d);
            return $r . ' ' . ($r > 1 ? $a_plural[$str] : $str) . ' ago';
        }
    }
}
Comment

PREVIOUS NEXT
Code Example
Php :: laravel migrations generator laravel 
Php :: how to make a comment in php 
Php :: destroy multiple sessions in laravel 
Php :: php invoke 
Php :: advantages of php 
Php :: convertir datetime a string en php 
Php :: php if boolean check 
Php :: laravel elequent query 
Php :: get category of current post wordpress 
Php :: laravel update email unique 
Php :: excerpt with Laravel 
Php :: toggle between login and logout buttons php 
Php :: filter array in php with passing extra params 
Php :: laravel permissions 
Php :: radio button select in php 
Php :: substract two datetime and get the different hours and minutes php 
Php :: php build query from array 
Php :: How to create a route in laravel? 
Php :: Notice: Array to string conversion php 
Php :: magento2 get full details of order collection 
Php :: db seed in controller 
Php :: laravel on cascade set null 
Php :: symfony connect rabbitMQ 
Php :: laravel crud generator 
Php :: woocommerce return to shop custom url 
Php :: get node url from twig 
Php :: session forget laravel 
Php :: popular cms 
Php :: extend woocommerce user fields edit-account 
Php :: PDO encode result recordset to utf8 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =