Created
August 4, 2012 19:14
-
-
Save rolandinsh/3259435 to your computer and use it in GitHub Desktop.
calculate date from day of year in php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php $todayid = date("z"); // to get today's day of year | |
function dayofyear2date( $tDay, $tFormat = 'd-m-Y' ) { | |
$day = intval( $tDay ); | |
$day = ( $day == 0 ) ? $day : $day - 1; | |
$offset = intval( intval( $tDay ) * 86400 ); | |
$str = date( $tFormat, strtotime( 'Jan 1, ' . date( 'Y' ) ) + $offset ); | |
return( $str ); | |
} | |
echo dayofyear2date($todayid); | |
// Read more @author http://www.iamboredsoiblog.eu/2008/11/01/calculate-date-from-day-of-year-in-php/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment