Hi, when I need use dates in sourcemod, I don't see any tutorial or guide for use it. So, I decided make a simple guide for working with dates.
It's very simple, do you need this function:
PHP Code:
FormatTime(char[] buffer, int maxlength, const char[] format, int stamp)
Where:
- char[] buffer
- Destination string buffer.
- int maxlength
- Maximum length of output string buffer.
- const char[] format
- Formatting rules (passing NULL_STRING will use the rules defined in sm_datetime_format).
(You can see all information in the API:
https://sm.alliedmods.net/new-api/sourcemod/FormatTime
So, using this link:
http://www.cplusplus.com/reference/ctime/strftime/ we can obtain all the values that we want.
Example:
PHP Code:
int day, month, year;
new String:sday[10];
new String:smonth[10];
new String:syear[10];
FormatTime(sday, sizeof(sday), "%d"); // Obtain day
FormatTime(smonth, sizeof(smonth), "%m"); // Obtain month
FormatTime(syear, sizeof(syear), "%Y"); // Obtain year
day = StringToInt(sday);
month = StringToInt(smonth);
year = StringToInt(syear);
And with this, we can do all that we want (Compare dates, add days, etc.).
Regards