Location: PHPKode > scripts > date > date/index.php
<body style="font-family:tahoma;font-size:9pt;">
<?php

require_once('dateclass.php');

$d = new date();

$o_day = 27 ;
$o_month = 10 ;
$o_year = 2006 ;

echo "INPUT DATE :<br/>";
echo "Day: <b>$o_day</b><br/>Month: <b>$o_month</b><br/>Year: <b>$o_year</b><br/>" ;

$d->set_start_date( $o_day, $o_month, $o_year ) ;

echo "<br/>";

echo "Days from January 1st $o_year : <b>".$d->daysfrombegin()."</b><br/>";
echo "Days to December 31th $o_year : <b>".$d->daystoend()."</b><br/>";
echo "Is <b>$o_year</b> bisextile ? " ;
echo ( $d->isbisextile( $o_year ) ) ? "<b>YES</b>" : "<b>NO</b>" ;

$days = -117 ;
$d->to_date( $days );
$date_array = $d->get_end_all_date() ;

$day = $date_array[0] ;
$month = $date_array[1] ;
$year = $date_array[2] ;

echo "<br/><br/>The date $o_day/$o_month/$o_year within <b>$days</b> days is : $day/$month/$year<br/>";

$days = 249 ;
$d->to_date( $days );
$date_array = $d->get_end_all_date() ;

$day = $date_array[0] ;
$month = $date_array[1] ;
$year = $date_array[2] ;

echo "The date $o_day/$o_month/$o_year within <b>$days</b> days is : $day/$month/$year<br/><br/";

$sd = 15; $sm = 5; $sy = 2006 ;
$ed = 1; $em = 1; $ey = 2006 ;

$days = $d->daysbetween($sd,$sm,$sy,$ed,$em,$ey) ;

echo "The days between <b>$sd/$sm/$sy</b> and <b>$ed/$em/$ey</b> are <b>".$days."</b> days<br/>";
/////////////////////////////////////////////////////////////////////////////////////////////////
$months = 14 ;
$d->to_months( $months );
$date_array = $d->get_end_all_date() ;

$day = $date_array[0] ;
$month = $date_array[1] ;
$year = $date_array[2] ;
echo "<br/>The date $o_day/$o_month/$o_year within <b>$months</b> months is : $day/$month/$year<br/>";
/////////////////////////////////////////////////////////////////////////////////////////////////
$month_name = $d->get_end_month_name() ;
echo "The verbose date of $day/$month/$year is : <b>$day $month_name $year</b><br/>";
/////////////////////////////////////////////////////////////////////////////////////////////////
$years = -156 ;
$d->to_years( $years );
$date_array = $d->get_end_all_date() ;

$day = $date_array[0] ;
$month = $date_array[1] ;
$year = $date_array[2] ;
echo "<br/>The date $o_day/$o_month/$o_year within <b>$years</b> years is : $day/$month/$year<br/>";

$d->set_start_date( $o_day, $o_month, $o_year ) ;
$date_array = $d->get_start_all_date() ;

$day = $date_array[0] ;
$month = $date_array[1] ;
$year = $date_array[2] ;

$month_name = $d->get_start_month_name() ;

echo "The verbose date of $o_day/$o_month/$o_year is : <b>$day $month_name $year</b><br/><br/>";
/////////////////////////////////////////////////////////////////////////////////////////////////
echo "The weekday of $o_day/$o_month/$o_year is <b>".$d->get_start_day_name()."</b><br/><br/>" ;

$sh = 23 ; $sm = 15 ; $ss = 33 ;
$eh = 2 ; $em = 23 ; $es = 8 ;

$time = $d->timebetween( $sh, $sm, $ss, $eh, $em, $es);

echo "START TIME : <b>$sh</b> hours, <b>$sm</b> minutes, <b>$ss</b> seconds<br>" ;
echo "END TIME : <b>$eh</b> hours, <b>$em</b> minutes, <b>$es</b> seconds<br>" ;

echo "TIME ELAPSED : <b>".$time['hours']."</b> hours, <b>".$time['minutes']."</b> minutes, <b>".$time['seconds']."</b> seconds<br>" ;

echo "<br>ADVANCED EXAMPLE INVOLVING DATE AND TIME<br><br>";

// START DATETIME ///////////////////////
$sday = 15; $smonth = 5; $syear = 2006 ;
$shour = 19 ; $sminute = 48 ; $ssecond = 31 ;

// END DATETIME ///////////////////////
$eday = 1; $emonth = 1; $eyear = 2006 ;
$ehour = 5 ; $eminute = 35 ; $esecond = 17 ;
echo "START TIMEDATE : <b>$shour</b> hours, <b>$sminute</b> minutes, <b>$ssecond</b> seconds of <b>$smonth</b>/<b>$sday</b>/<b>$syear</b><br>" ;
echo "END TIMETIME : <b>$ehour</b> hours, <b>$eminute</b> minutes, <b>$esecond</b> seconds of <b>$emonth</b>/<b>$eday</b>/<b>$eyear</b><br>" ;

$time = $d->timebetween( $shour, $sminute, $ssecond, $ehour, $eminute, $esecond, $bOneDayOut );
$days = $d->daysbetween( $sday, $smonth, $syear, $eday, $emonth, $eyear, $bBackwards ) ;

$days = abs( $days ) ;

if ( $bBackwards && $bOneDayOut ) $days = -$days + 1 ;
else if ( !$bBackwards && $bOneDayOut ) $days-- ;

$hhmmss = $d->format_time( $time['hours'], $time['minutes'], $time['seconds'], "", ":" ) ;

echo "The time between is <b>$days</b> days and <b>$hhmmss</b> hours<br/><br/>";

$sHOURS = 16 ; $sMINUTES = 13 ; $sSECONDS = 59 ;
$withinHOURS = 3 ; $withinMINUTES = 59 ; $withinSECONDS = 54 ;

$time = $d->to_time( $sHOURS, $sMINUTES, $sSECONDS, $withinHOURS, $withinMINUTES, $withinSECONDS );

echo "START TIME : <b>".$d->format_time( $sHOURS, $sMINUTES, $sSECONDS, "hhmmss", ":" )."</b><br>";
echo "ELAPSED TIME : <b>".$d->format_time( $withinHOURS, $withinMINUTES, $withinSECONDS, "hhmmss", ":" )."</b><br>";
echo "FINAL TIME : <b>".$d->format_time( $time['hours'], $time['minutes'], $time['seconds'], "hhmmss", ":" )."</b><br>";

$sHOURS = 3 ; $sMINUTES = 02 ; $sSECONDS = 38 ;
$withinHOURS = -6 ; $withinMINUTES = 59 ; $withinSECONDS = 54 ;

$time = $d->to_time( $sHOURS, $sMINUTES, $sSECONDS, $withinHOURS, $withinMINUTES, $withinSECONDS );

echo "<br>";
echo "START TIME : <b>".$d->format_time( $sHOURS, $sMINUTES, $sSECONDS, "hhmmss", ":" )."</b><br>";
echo "ELAPSED TIME : <b>".$d->format_time( $withinHOURS, $withinMINUTES, $withinSECONDS, "hhmmss", ":" )."</b><br>";
echo "FINAL TIME : <b>".$d->format_time( $time['hours'], $time['minutes'], $time['seconds'], "hhmmss", ":" )."</b><br>";
?>
Return current item: date