Merubah timestamp menjadi 1 jam yang lalu 1 minggu yang lalu dll.

if ($db_count = mysqli_num_rows ($db_query)) {

    while ($db_row = mysqli_fetch_array ($db_query)) {

        $order_id = $db_row ["id"];

        $aktif = ($db_row["status"] == 'aktif');

$non = ($db_row["status"] == 'non');

$id_pengirim = $db_row["id_pengirim"];

$reviews = $db_row["reviews"];

$stamp = $db_row["stamp"];

if ($id_pengirim) {

            $pengirim_query = mysqli_query ($mysqli, "select * from wp_account where id = '$id_pengirim' limit 1");

            if ($pengirim_count = mysqli_num_rows ($pengirim_query)) {

                $pengirim_row = mysqli_fetch_array ($pengirim_query);

                $pengirim_name = $pengirim_row ["name"];

                $pengirim_photo = $pengirim_row ["photo"];

                }

            }

         if ($id_customer) {

            $customer_query = mysqli_query ($mysqli, "select * from wp_account where id = '$id_customer' limit 1");

            if ($customer_count = mysqli_num_rows ($customer_query)) {

                $customer_row = mysqli_fetch_array ($customer_query);

                $customer_name = $customer_row ["name"];

                $customer_photo = $customer_row ["photo"];

                }

            }

        $waiting = ($db_row["status"] == 'waiting');

$process = ($db_row["status"] == 'process');

$done = ($db_row["status"] == 'done');

date_default_timezone_set ("Asia/Jakarta");

function time_elapsed_string($datetime, $full = false) {

    $now = new DateTime;

    $ago = new DateTime($datetime);

    $diff = $now->diff($ago);

    $diff->w = floor($diff->d / 7);

    $diff->d -= $diff->w * 7;

    $string = array(

        'y' => 'tahun',

        'm' => 'bulan',

        'w' => 'minggu',

        'd' => 'hari',

        'h' => 'jam',

        'i' => 'menit',

        's' => 'detik',

    );

    foreach ($string as $k => &$v) {

        if ($diff->$k) {

            $v = $diff->$k . ' ' . $v . ($diff->$k > 1 ? 's' : '');

        } else {

            unset($string[$k]);

        }

    }

    if (!$full) $string = array_slice($string, 0, 1);

    return $string ? implode(', ', $string) . ' yang lalu' : 'barusan aja';

}

echo time_elapsed_string('@1596420234');

echo time_elapsed_string($stamp);

        ?>

Output:

2 jam yang lalu

barusan saja

-------------------------------------------------------------------------

Bagaimana memasukkan variabel $stamp ke baris yang ini?

echo time_elapsed_string('@1596420234');

Mohon petunjuknya teman2..

avatar imamalhizami_google
@imamalhizami_google

1 Kontribusi 0 Poin

Dipost 4 tahun yang lalu

Belum ada Jawaban. Jadi yang pertama Jawaban

Login untuk ikut Jawaban