home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Join TechIMO for Free!
Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read
Reply Get bargains at  »  Dealighted.com
 
Thread Tools
Currently Active Users: 2712
Discussions: 188,384, Posts: 2,243,505, Members: 232,615
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


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Most Active Discussions
Is It Just Me? (2896)
CPU wont boot (5)
3-days in and no threads about Gaza (160)
The United States Debt (20)
I think I just killed my computer w.. (24)
hp compaq nc6000 problems (139)
Upgrading RAM (5)
Folderchat Weekday thread (442)
Antec 300 bulk purchase? (11)
Recent Discussions
Building a gaming computer advi.. (4)
hp compaq nc6000 problems (139)
Folderchat Weekday thread (442)
CPU wont boot (5)
Creative T-3000 Subwoofer (3)
ACPI controller halt on boot (2)
Worth the upgrade?? (15)
ADVICE (0)
How to increase my ram? (5)
Blackberry Storm, Gears of War .. (1)
Core 2 Quad Q9550 system (3)
COWBOOM Ripoff! Used Laptop w/$.. (4)


All times are GMT -4. The time now is 10:16 PM.
TechIMO Copyright 2008 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