Skip to content

Instantly share code, notes, and snippets.

View turtlix's full-sized avatar
:octocat:

Andri Andreas Priyanto turtlix

:octocat:
View GitHub Profile
/***********************************************************
******* SIMPLE TEST **/
class A {
function t() {
echo get_calling_class();
}
}
class B {
<?php
$dt_end = new DateTime('December 3, 2016 2:00 PM');
$remain = $dt_end->diff(new DateTime());
echo $remain->d . ' days and ' . $remain->h . ' hours';
<?php
function _ago($tm,$rcs = 0) {
$cur_tm = time(); $dif = $cur_tm-$tm;
$pds = array('second','minute','hour','day','week','month','year','decade');
$lngh = array(1,60,3600,86400,604800,2630880,31570560,315705600);
for($v = sizeof($lngh)-1; ($v >= 0)&&(($no = $dif/$lngh[$v])<=1); $v--); if($v < 0) $v = 0; $_tm = $cur_tm-($dif%$lngh[$v]);
$no = floor($no); if($no <> 1) $pds[$v] .='s'; $x=sprintf("%d %s ",$no,$pds[$v]);
if(($rcs == 1)&&($v >= 1)&&(($cur_tm-$_tm) > 0)) $x .= time_ago($_tm);
<?php
$start_date = new DateTime('2010-10-01');
$end_date = new DateTime('2010-10-05');
$period = new DatePeriod(
$start_date, // 1st PARAM: start date
new DateInterval('P1D'), // 2nd PARAM: interval (1 day interval in this case)
$end_date, // 3rd PARAM: end date
DatePeriod::EXCLUDE_START_DATE // 4th PARAM (optional): self-explanatory
<?php
function age($date){
$time = strtotime($date);
if($time === false){
return '';
}
$year_diff = '';
$date = date('Y-m-d', $time);
<?php
if(strtotime(dateString) > time()) {
# date is in the future
}
if(strtotime(dateString) < time()) {
# date is in the past
}
<?php
function dateDiff($date1, $date2){
$datetime1 = new DateTime($date1);
$datetime2 = new DateTime($date2);
$interval = $datetime1->diff($datetime2);
return $interval->format('%H:%I');
}
<?php
function convertToHoursMins($time, $format = '%02d:%02d') {
if ($time < 1) {
return;
}
$hours = floor($time / 60);
$minutes = ($time % 60);
return sprintf($format, $hours, $minutes);
}
<?php
function weeknumber($ddate){
$date = new DateTime($ddate);
return $date->format("W");
}
<?php
$originalDate = "2010-03-21";
$newDate = date("d-m-Y", strtotime($originalDate));