AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   [Guide] Working with dates (https://forums.alliedmods.net/showthread.php?t=272095)

jaxoR 09-23-2015 17:38

[Guide] Working with dates
 
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

Powerlord 09-24-2015 21:51

Re: [Guide] Working with dates
 
GetTime returns the number of seconds since 1970 January 1 00:00:00 UTC. Might be easier to do math on that instead.

sdz 09-29-2015 04:41

Re: [Guide] Working with dates
 
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 10-01-2015 18:39

Re: [Guide] Working with dates
 
Quote:

Originally Posted by EasSidezz (Post 2348088)
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.

http://www.mendozapost.com/files/ima...f5dc94d356.gif

Addicted. 10-01-2015 20:40

Re: [Guide] Working with dates
 
Quote:

Originally Posted by jaxoR (Post 2348760)

:bacon!:


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

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