Can you be more specific on what you're looking for? Today is Feb 16, 2010, and you say that this should be year 2010, but that sept 1 2010 should be 2011?
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
I need show to the year for the the next 1st September dynamically, i.e. the function returns the year without any date string entered.
For example
Today (16/02/2010) would return 2010
but from 01/09/2010 the next 1st September would be in the year 2011
on 20/04/2011 the next 1st September would be in the year 2011
2011 would be returned right up until 1st September 2011, when it would then return 2012.
I need something that will run happily without any manual changing of date string.
Let me know if you need any more information or if I'm still not explaining clearly
function next_year_by_month( $month = NULL ) { // no month specified... use current, which will always return next year if ( NULL === $month ) { return 1 + date( 'Y' ); } // build a timestamp based on the selected month $mktime = mktime( 0, 0, 0, ( int ) $month ); // grab the associated year $year = ( int ) date( 'Y', $mktime ); // if month is current or in the past, reflect the next year if ( date( 'Y-m' ) >= date( 'Y-m', $mktime ) ) { $year++; } // send it on it's way return $year; }
PHP Code:
// Today is Feb 16, 2010 (2010/02/16)
// Current month echo next_year_by_month(); // 2011
No idea if it works, I'm at work so I can't test it. Works alright in my head though
Edit:
Bah, way too slow today >.<
Edit:
OHHHHHHHHH! I guess I didn't getcha lol.
Yes, use kblums, I completely ignored the fact that this should cover past months as well (as in, its not sensitive to the year change). I would expect that mine should return 2010 if provided with a time created in january, instead of 2011 as it should.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php