home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Ask a Tech Support Question (free)!

Finding day of week

Reply
Get bargains at  »  Dealighted.com
 
Thread Tools Search this Thread
Currently Active Users: 1526
Discussions: 200,952, Posts: 2,379,478, Members: 246,322
Old January 15th, 2003, 07:16 PM   Digg it!   #1 (permalink)
Banned
 
qball's Avatar
 
Join Date: Oct 2001
Posts: 447
Finding day of week

This could be for any language. Should be pretty easy.

don't you hate when you work on something, and you get brainfreeze and all of sudden you're dumber than a box of rocks...

anyway, here's the deal. you are given:

0 = sunday ... 6 = saturday
//I personally prefer 1-7, but...
startday of given month. ie. for jan 2003, the first is on a wednesday, or as defined 3.
a day of the month. for jan 2003, 1-31.

return the day of the week for the day of the month.

so if we have integer calcdow(int startday, int dayofmonth), the above example would be

calcdow(3, 1) returns 3.

or

calcdow(3, 15) returns 3. as today is wednesday.

a very poor way would be:
Code:
public integer calcdow(int startday, int dayofmonth)
{
	for (int i= 1; i < dayofmonth; i++) 
	{
		startday++;
		if (startday == 7)
		{
			startday =0;
		}
	}
	
	return startday;
}
DOH!, brainfreeze just left, nevermind, as:

dayofweek = dayofmonth%7 + startday - 1;

sometimes you just have to step away from the issue....
qball is offline   Reply With Quote
Old January 15th, 2003, 07:18 PM     #2 (permalink)
Ultimate Member
 
chris64's Avatar
 
Join Date: Oct 2002
Location: SoCal
Posts: 1,494
Got an idea get a calendar. ROFL.
__________________
Got Jesus?
chris64 is offline   Reply With Quote
Old January 15th, 2003, 07:22 PM     #3 (permalink)
dword to your moms
 
krohnjw's Avatar
 
Join Date: Oct 2001
Location: ~/
Posts: 3,195
Send a message via AIM to krohnjw
Hm, or help him with his coding....i believe either would be a constructive post....or would only one......
The last should work to find the day of the week.
krohnjw is offline   Reply With Quote
Old January 15th, 2003, 11:39 PM     #4 (permalink)
Banned
 
qball's Avatar
 
Join Date: Oct 2001
Posts: 447
it's OK.

Quote:
Got an idea get a calendar. ROFL.

useless posting seems common, as this thread shows.

ROFL,

[flart]
what calendar do you use?
[/flart]
qball is offline   Reply With Quote
Old January 27th, 2003, 10:54 PM     #5 (permalink)
Banned
 
qball's Avatar
 
Join Date: Oct 2001
Posts: 447
very curious.

Code:
dayofweek = dayofmonth%7 + startday - 1;
nobody even tried code to see if it works? as it doesn't.

lol.
qball is offline   Reply With Quote
Old January 28th, 2003, 04:12 PM     #6 (permalink)
Senior Member
 
Join Date: Oct 2001
Location: New Hampshire, USA
Posts: 641
I don't know if this is of value to you, but there is a DATEDIFF function detailed within the MSDN website.

I have used this function to exclude weekends when determining the number of days early/late a delivery was received.

EDIT: http://msdn.microsoft.com/library/de...ctdatediff.asp
ctaylor is offline   Reply With Quote
Old January 28th, 2003, 11:00 PM     #7 (permalink)
Banned
 
qball's Avatar
 
Join Date: Oct 2001
Posts: 447
thanks.

I was working with some other code (let's say inherited, lol, not OO inherited), and my opinion of that code, is, eh..ah..no comment.

the solution was simple:

date datatypes generally have info one needs given various date/time functions (DB, scripting, lang...). as in:

value of "1/28/03" (whatever format), already knows it is:

Monday, the 82th of 1203bc????

sorry, but "0" == sunday?, even if done for easy loop indexing, not good idea.
qball is offline   Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Most Active Discussions
Is It Just Me? (2943)
The disrespect of Obama by Russian .. (41)
Making Health Care Worse (178)
Wireless Televisions. (12)
CPU fan stops spinning randomly (9)
Regular Build (11)
windows 7 problem (7)
Is the PSU I received dead? (12)
radeon x850xt platinum & shader.. (6)
Print spooler problem (15)
HIS HD5770 graphic card question (15)
windows vista security holes (10)
Install XP pro and a Vista laptop ?.. (11)
Foreign voltage (10)
Recent Discussions
tv not turn on-makes clicking sound (2)
SELLING FRESH,CVV,LOGINS,DUMPS,TRACKS.. (0)
CPU fan stops spinning randomly (9)
EVGA 9800 gtx help with finding a goo.. (11)
Regular Build (11)
Help with onclick and buttons (0)
Modern Warfare 2: Who Bought It? (63)
Virus advise (8)
My monitor won't turn on after instal.. (1)
Laptop with wireless problem. (3)
Internet Lost (3)
Dept. of HS: NSA 'Helped' Develop Vis.. (16)
windows vista security holes (10)
Point and Shoot Camera Suggestions. (4)
Multiple Restarts Required at Boot (2)
Ideal cheap graph card for PC-Gaming? (18)
radeon x850xt platinum & shader 3 (6)
Graphics Card Upgrade Question (4)
For Sale BFG GTX285 OC2 with 10 year .. (3)
How to convert MP3's (4)
Wireless Televisions. (12)
Hp Artist Edition + Matching Bag (0)
Asus P4G8X Mobo (6)
Xbox 360 GTA: SA disk error (1)
Is the PSU I received dead? (12)


All times are GMT -4. The time now is 05:01 AM.
TechIMO Copyright 2009 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28