Adsense
Popular Posts
- Code update from PHP 7.4 to PHP 8.1 - PhpSpreadsheet
- MySQL workbench -"Could not decrypt password cache"
- Code update from PHP 7.4 to PHP 8.1 - Worksheet/Iterator.php
- Rendering HTML tags inside textarea
- axios handle blob type data
- Unix Utils and wget in Windows
- increase mysql query speed
- Setup vi syntax for PHP
- EXCEL return to the next line in the same cell
- Get WAMP running on EC2
Thursday, September 25, 2014
Convert MySQl date format to PHP, convert date to term
In MySQl, the date format is yyyy-m-d.
To change to date format in PH, $dateMySQL below is MySQl date format yyyy-m-d.
$date = strtotime($dateMySQL);
$year = date("Y", $date );
$month = date("n", $date);
$day = date("j", $date );
$year, $month, $day is to extract year, month and day. strtotime is to convert format time to to unix time.
Below is an example to convert MySQL date format to SFU term. and return the style of box shadow
in red.
function style_for_initialcredit($termkey, $datecredit) {
$date = strtotime($datecredit);
$year = date("Y", $date );
$month = date("n", $date);
$day = date("j", $date );
if($month>=1 && $month<=4) {$term = ($year-1900)*10+1;}
elseif($month>=5 && $month<=8) {$term = ($year-1900)*10+4;}
elseif($month>=9 && $month<=12) {$term = ($year-1900)*10+7;}
else $term = 0;
$style = "";
if($term==$termkey)
$style .=" box-shadow: inset -10px 0 5px -5px hsla(0,100%,50%,0.5); ";
return trim($style);
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment