forked from if-itb/IF3110-01-Simple-Blog
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsql_my.php
More file actions
45 lines (39 loc) · 1.37 KB
/
sql_my.php
File metadata and controls
45 lines (39 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
date_default_timezone_set("Asia/Jakarta");
function date_sql2my($sql_date) {
$timestamp = date_create_from_format('Y-m-d', $sql_date);
return $timestamp->format('d-m-Y');
}
function date_sql2my0($sql_date) {
$timestamp = date_create_from_format('Y-m-d', $sql_date);
$month_name = array(1 => "Januari", "Februari", "Maret", "April", "Mei",
"Juni", "Juli", "Agustus", "September", "Oktober", "November",
"Desember");
return $timestamp->format('d ') . $month_name[+$timestamp->format('m')]
. $timestamp->format(' Y');
}
function time_passed($sql_date_time) {
$timestamp = date_create_from_format('Y-m-d H:i:s', $sql_date_time);
$now = new DateTime();
$difference = $now->diff($timestamp);
//return $now->format("Y-m-d H:i:s");
if ($difference->d == 0) {
if ($difference->h == 0) {
if ($difference->i == 0) {
if ($difference->s == 0) {
return "Barusan Saja";
} else {
return $difference->s. " detik yang lalu";
}
} else {
return $difference->i.' menit yang lalu';
}
} else {
return $difference->h.' jam, '.$difference->i.' menit yang lalu';
}
} else {
return $sql_date_time;
}
return "ERROR";
}
?>