Adsense
Popular Posts
- Install APXS in Redhat Linux
- MySQL workbench -"Could not decrypt password cache"
- Transfer modules between sites
- JavaScript, remove trailing insignificant zeros after toFixed function
- Set Windows path command line
- datatable order by nunmeric
- MySQL date created and date modified
- super(props) in React
- PHP, dump varailbes in a format way
- React: connect(mapStateToProps, mapDispatchToProps)
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