forked from WWBN/AVideo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainObject.php
executable file
·48 lines (47 loc) · 1.39 KB
/
mainObject.php
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
46
47
48
<?php
class Main {
/**
* receive a YYYY-MM-DD
* @param type $brDate
* @return String dd/mm/yyyy
*/
static public function dateMySQLToBrString($mySqlDate) {
$parts = explode('-', $mySqlDate);
//switch month and day
if (empty($parts[2])) {
return $mySqlDate;
} else {
if (strlen($parts[2]) > 2) { // if there is hour
$parts2 = explode(" ", $parts[2]);
$day = $parts2[0];
$hour = " " . $parts2[1];
} else {
$day = $parts[2];
$hour = "";
}
return "{$day}/{$parts[1]}/{$parts[0]}{$hour}";
}
}
/**
* receive a DD/MM/YYYY
* @param type $mySqlDate
* @return String YYYY-mm-dd
*/
static public function dateBrStringToMySQL($date) {
$parts = explode("/", $date);
//switch month and day
if (empty($parts[2])) {
return $date;
} else {
if (strlen($parts[2]) > 4) { // if there is hour
$parts2 = explode(" ", $parts[2]);
$year = $parts2[0];
$hour = " " . $parts2[1];
} else {
$year = $parts[2];
$hour = "";
}
return "{$year}-{$parts[1]}-{$parts[0]}{$hour}";
}
}
}