PDA

View Full Version : Getting the DAY of the week...


=|[76AD]|= TatsuSaisei
08-15-2006, 02:38 PM
I was not sure where to put this so I plopped it here.... back a few months ago I was writing a plugin for my clan, and we needed certain actions to take place on certain days of the week. I could not find a way to simply get this info from the Server, or game engine, so I made a function that "calculated" the day of the week based off of the date, month and year....

I figured I have asked for so much, and have gotten alot of replies and help that it is time for me to give something back.... I know alot of people could make some nice things with a function like this...

so here it is... (this is NOT a complete plugin, just the bits of code that do the function)




#define PLUGIN "Get Day of Week"
#define VERSION "1.0"
#define AUTHOR "=|[76AD]|= TatsuSaisei"

new theday[16] //variable to use in a condition statement, depending on what you want to do...

public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR)
// Add your init code here.
set_task(60.0,"GetDOW",1,"",0,"b")
}

public GetDOW()
{
new xmonth,xdate,xyear,w,day
date(xyear,xmonth,xdate)
switch(xmonth){
case 01:{
xmonth = 13
xyear = xyear - 1
}
case 02:{
xmonth = 14
xyear = xyear - 1
}
}
w = xdate + (2 * xmonth) + floatround(0.6 * (xmonth + 1), floatround_floor) + xyear + floatround(float(xyear)/4.0, floatround_floor) - floatround(float(xyear)/100.0, floatround_floor) + floatround(float(xyear)/400.0, floatround_floor) + 2
day = w % 7
switch(day){
case 0:{
theday = "Saturday"
}
case 1:{
theday = "Sunday"
}
case 2:{
theday = "Monday"
}
case 3:{
theday = "Tuesday"
}
case 4:{
theday = "Wednesday"
}
case 5:{
theday = "Thursday"
}
case 6:{
theday = "Friday"
}
}

return PLUGIN_CONTINUE
}


It works and works well... and is easy to incorporate into anything... I am actually in the process of writing a plugin to force a server to "quit" in an effort to automatically "reboot" or restart the server, knowing my provider and many others use a script that restarts a server when it crashes or is shut off...

so here is my gift to the developers who have helped me, and for the rest who are learning to code...

alex_bfg
08-23-2006, 10:23 AM
nice i hope my plugin will work you all will love-it

PopeHannibal
08-31-2006, 09:48 PM
Not to say this isn't nice, but I don't see the advantage of this over get_time?

From Funcwiki:
get_time ( const format[],output[],len )

%a abbreviated weekday name (Sun)
%A full weekday name (Sunday)
%b abbreviated month name (Dec)
%B full month name (December)
%c date and time (Dec 2 06:55:15 1979)
%d day of the month (02)
%H hour of the 24-hour day (06)
%I hour of the 12-hour day (06)
%j day of the year, from 001 (335)
%m month of the year, from 01 (12)
%M minutes after the hour (55)
%p AM/PM indicator (AM)
%S seconds after the minute (15)
%U Sunday week of the year, from 00 (48)
%w day of the week, from 0 for Sunday (6)
%W Monday week of the year, from 00 (47)
%x date (Dec 2 1979)
%X time (06:55:15)
%y year of the century, from 00 (79)
%Y year (1979)

%w would allow you to determine the current day of the week, seems abit simpler :D

diamond-optic
08-31-2006, 09:59 PM
lol ive never seen those before.. guess i should start looking thru the wiki a bit more instead of just the include files & trying to find my way thru the hlsdk

=|[76AD]|= TatsuSaisei
08-31-2006, 11:57 PM
Not to say this isn't nice, but I don't see the advantage of this over get_time?

From Funcwiki:
get_time ( const format[],output[],len )

%a abbreviated weekday name (Sun)
%A full weekday name (Sunday)
...
%w would allow you to determine the current day of the week, seems abit simpler :D

Well... at the time I did not have this information, until NOW.... yeah its a bit "much" now in the face of this, but it served its purpose at the time... and since there has never been full documentation of any magnitude, information was limited to what was on hand at the time...

but I thank you tremendously for bringing to light information that will save me alot of code...

EDIT: The comment you refer to was posted 4 months ago... lol, and I had used this script for far longer... so that would explain why at the time, I used this to get what I needed... trying %A to get the name of the day of the week, was just something I would not have thought of immediately... lol

So yeah, my code is now overkill...

diamond-optic
09-01-2006, 12:04 AM
hah aint it funny how that all worked out...


happens alot to me hehe