Skip to content

Instantly share code, notes, and snippets.

@rolandinsh
Created August 4, 2012 19:14
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rolandinsh/3259435 to your computer and use it in GitHub Desktop.
Save rolandinsh/3259435 to your computer and use it in GitHub Desktop.
calculate date from day of year in php
<?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