AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Next Friday Date (https://forums.alliedmods.net/showthread.php?t=221392)

1liornatan 07-21-2013 11:33

Next Friday Date
 
Hello,
I know that I can use date() in order to get the current date,
but I would like to know how can i get the next friday's date.

Thanks.

YamiKaitou 07-21-2013 11:39

Re: Next Friday Date
 
1 day is 86400 seconds, so just use math to determine it

1liornatan 07-21-2013 13:50

Re: Next Friday Date
 
maybe it will be easier to get the current date and the current day??
but if you think that your way is easier can you write me an example?
thanks.

YamiKaitou 07-21-2013 14:18

Re: Next Friday Date
 
Obtain the current Day of the Week
Then determine how many days away Friday is
Then add that many days in seconds to the current timestamp
Obtain the date of the new timestamp

Black Rose 07-21-2013 17:04

Re: Next Friday Date
 
Code:
    new add_days[] = {1,7,6,5,4,3,2} // get_systime() starts on a thursday         new curTime = get_systime() + 7200;         new curWeekday = curTime % 604800 / 86400;         new output[32];     format_time(output, 31, "%Y-%m-%d", curTime + add_days[curWeekday] * 86400);     server_print("Next Friday is: %s", output);

This assumes you want to start displaying next weeks friday as soon as this friday begins. If you want it to change after this friday is over you just change
Code:
new add_days[] = {1,7,6,5,4,3,2}
to
Code:
new add_days[] = {1,0,6,5,4,3,2}

fysiks 07-21-2013 18:06

Re: Next Friday Date
 
Using floatround_floor for division is the same as integer division. I.e. you can simply do: "( curTime % 604800 ) / 86400"

Also, the code will break after February 29th, 2016 due to leap years.

Black Rose 07-21-2013 18:27

Re: Next Friday Date
 
Quote:

Originally Posted by fysiks (Post 1995964)
Using floatroad_floor for division is the same as integer division. I.e. you can simply do: "( curTime % 604800 ) / 86400"

Also, the code will break after February 29th, 2016 due to leap years.

It counts weeks and then days within a week. Last time I checked weeks are not affected by leap years.

I changed to integers though, much better. Thank you.

I noticed now It's not calculating correctly. I've tried to fix it, but I don't understand it fully. I HATE date/time calculations.

fysiks 07-21-2013 21:43

Re: Next Friday Date
 
Quote:

Originally Posted by Black Rose (Post 1995969)
It counts weeks and then days within a week. Last time I checked weeks are not affected by leap years.

I've convinced myself that you are correct here. I was thinking of something else.

1liornatan 07-21-2013 21:49

Re: Next Friday Date
 
Thank you all, it works great!

Black Rose 07-22-2013 10:05

Re: Next Friday Date
 
Quote:

Originally Posted by 1liornatan (Post 1996087)
Thank you all, it works great!

Sorry to say it, but it doesn't.
But I will try fixing it today.


All times are GMT -4. The time now is 06:23.

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