Raised This Month: $ Target: $400
 0% 

Next Friday Date


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
1liornatan
Member
Join Date: Sep 2010
Old 07-21-2013 , 11:33   Next Friday Date
Reply With Quote #1

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.
1liornatan is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 07-21-2013 , 11:39   Re: Next Friday Date
Reply With Quote #2

1 day is 86400 seconds, so just use math to determine it
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
1liornatan
Member
Join Date: Sep 2010
Old 07-21-2013 , 13:50   Re: Next Friday Date
Reply With Quote #3

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.
1liornatan is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 07-21-2013 , 14:18   Re: Next Friday Date
Reply With Quote #4

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
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 07-21-2013 , 17:04   Re: Next Friday Date
Reply With Quote #5

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}

Last edited by Black Rose; 07-26-2013 at 11:26.
Black Rose is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-21-2013 , 18:06   Re: Next Friday Date
Reply With Quote #6

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.
__________________

Last edited by fysiks; 07-21-2013 at 21:21. Reason: typo
fysiks is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 07-21-2013 , 18:27   Re: Next Friday Date
Reply With Quote #7

Quote:
Originally Posted by fysiks View Post
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.

Last edited by Black Rose; 07-21-2013 at 21:05.
Black Rose is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-21-2013 , 21:43   Re: Next Friday Date
Reply With Quote #8

Quote:
Originally Posted by Black Rose View Post
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.
__________________
fysiks is offline
1liornatan
Member
Join Date: Sep 2010
Old 07-21-2013 , 21:49   Re: Next Friday Date
Reply With Quote #9

Thank you all, it works great!
1liornatan is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 07-22-2013 , 10:05   Re: Next Friday Date
Reply With Quote #10

Quote:
Originally Posted by 1liornatan View Post
Thank you all, it works great!
Sorry to say it, but it doesn't.
But I will try fixing it today.
Black Rose is offline
Reply



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


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