You can do this using the
Unix Time include.
With this you can add or subtract days to/from a date using a positive or negative number as iDaysToAdd, respectively. I included functions to do this to a date string or to a date value in integer format. The date string must be in 'DD.MM.YYYY' format for this to work properly.
Output:
Code:
New date=12.05.2016
PHP Code:
#include <amxmodx>
#include <unixtime>
new const Version[] = "0.1";
public plugin_init()
{
register_plugin( "Add Days to Date" , Version , "bugsy" );
register_concmd( "test" , "Test" );
}
public Test()
{
new szDate[] = "07.05.2016";
AddDays_String( szDate , charsmax( szDate ) , 5 );
server_print( "New date=%s" , szDate );
}
public AddDays_String( szDate[] , iMaxChars , iDaysToAdd )
{
new iDay , iMonth , iYear;
szDate[ 2 ] = EOS;
szDate[ 5 ] = EOS;
iDay = str_to_num( szDate[ 0 ] );
iMonth = str_to_num( szDate[ 3 ] );
iYear = str_to_num( szDate[ 6 ] );
AddDays( iDay , iMonth , iYear , iDaysToAdd );
return formatex( szDate , iMaxChars , "%02d.%02d.%04d" , iDay , iMonth , iYear );
}
public AddDays( &iDay , &iMonth , &iYear , iDaysToAdd )
{
new iNewDate , iHours , iMinutes , iSeconds;
iNewDate = TimeToUnix( iYear , iMonth , iDay , 0 , 0 , 0 );
iNewDate += ( iDaysToAdd * 86400 );
UnixToTime( iNewDate , iYear , iMonth , iDay , iHours , iMinutes , iSeconds );
}
__________________