Raised This Month: $ Target: $400
 0% 

[SOLVED] Add X days in a date


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-07-2016 , 13:41   Re: Add X days in a date
Reply With Quote #2

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_StringszDate charsmaxszDate ) , );
    
    
server_print"New date=%s" szDate );
}

public 
AddDays_StringszDate[] , iMaxChars iDaysToAdd )
{
    new 
iDay iMonth iYear;
    
    
szDate] = EOS;
    
szDate] = EOS;    
    
    
iDay str_to_numszDate] );
    
iMonth str_to_numszDate] );
    
iYear str_to_numszDate] );
    
    
AddDaysiDay iMonth iYear iDaysToAdd );
    
    return 
formatexszDate iMaxChars "%02d.%02d.%04d" iDay iMonth iYear );
}

public 
AddDays( &iDay , &iMonth , &iYear iDaysToAdd )
{
    new 
iNewDate iHours iMinutes iSeconds;
    
    
iNewDate TimeToUnixiYear iMonth iDay );
    
    
iNewDate += ( iDaysToAdd 86400 );
    
    
UnixToTimeiNewDate iYear iMonth iDay iHours iMinutes iSeconds );

__________________
Bugsy is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:38.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode