Raised This Month: $ Target: $400
 0% 

[Guide] Working with dates


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
jaxoR
Member
Join Date: Dec 2014
Location: Argentina
Old 09-23-2015 , 18:38   [Guide] Working with dates
Reply With Quote #1

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[] bufferint maxlength, const char[] formatint 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).
  • int stamp
    • Optional time stamp.

(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 daymonthyear;

new 
String:sday[10];
new 
String:smonth[10];
new 
String:syear[10];

FormatTime(sdaysizeof(sday), "%d"); // Obtain day
FormatTime(smonthsizeof(smonth), "%m"); // Obtain month
FormatTime(syearsizeof(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
jaxoR is offline
 


Thread Tools
Display Modes

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 23:31.


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