Raised This Month: $ Target: $400
 0% 

[Guide] Working with dates


Post New Thread Reply   
 
Thread Tools Display Modes
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
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 09-24-2015 , 22:51   Re: [Guide] Working with dates
Reply With Quote #2

GetTime returns the number of seconds since 1970 January 1 00:00:00 UTC. Might be easier to do math on that instead.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
sdz
Senior Member
Join Date: Feb 2012
Old 09-29-2015 , 05:41   Re: [Guide] Working with dates
Reply With Quote #3

Nice tutorial. I was going to write a guide eventually on using time/dates and using them in reference to the future/past but I can see you did a good 30% of that.
sdz is offline
jaxoR
Member
Join Date: Dec 2014
Location: Argentina
Old 10-01-2015 , 19:39   Re: [Guide] Working with dates
Reply With Quote #4

Quote:
Originally Posted by EasSidezz View Post
Nice tutorial. I was going to write a guide eventually on using time/dates and using them in reference to the future/past but I can see you did a good 30% of that.
jaxoR is offline
Addicted.
AlliedModders Donor
Join Date: Dec 2013
Location: 0xA9D0DC
Old 10-01-2015 , 21:40   Re: [Guide] Working with dates
Reply With Quote #5

Quote:
Originally Posted by jaxoR View Post
Addicted. is offline
Reply


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 22:58.


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