Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Determining Day of Week in SQL 2000 or ASP

Status
Not open for further replies.

Dynapen

Programmer
Apr 20, 2000
245
US
I am working a program where a certain variable is determined by what date the user is selecting. If the date is a weekday, then my variable is one thing, if it's the weekend, then its another value.
I know that in MS Access there is a function to return a value of 1-7 depending on the day of the week. Is there a way to do the same thing, preferably in ASP so that I can perform this function without running to the database first. But if not, is there a way to do it in SQL Server 2000?

Any help you can provide would be greatly appreciated.

Thanks in advance guys.
 
use day(getdate())

ex:

select * from tbl
where day = day(getdate())

that will get all the records from the tbl where day = today's date.

note: this works in 7.0, i'm not sure about 2K. It should though...

look in BOL for day or getdate


hth
leo leo
 
I know that the VBScript function weekday will give me the value, as will the javascript funciton getday(). The problems is that I can't get either one of them to work. I am trying to use the javascript function below. The page orders the the function called returndate, and passes the variable to it.

function returnDate(inDay)
{
var day = inDay;
var month = (document.calControl.month.selectedIndex)+1;
var year = document.calControl.year.value;
var time = (returntime(day));

if ((""+month).length == 1)
{
month="0"+month;
}
if ((""+day).length == 1)
{
day="0"+day;
}
if (day != " ") {
dateField.value = month + "/" + day + "/" + year + " " + time;
window.close()
}
}

By my understanding this should tell this function to call the function returntime, and to pass it the varialbe Day, that is declared above in the returndate function. Here is the returntime function

function returntime(day) {
var doy;
doy = day.getday();
if (doy == 0 || doy == 6) {
time = ('08:00');}
else {
time = ('16:30');}
return(time);
}

But when I do this, it not only doesn't return a time, but it stops the returndate function from returning a value as well.

Help Please.....
 
sorry - you might need to do this:

function returntime(day) {
var myDate = new Date(), doy;
doy = myDate.getday();
if (doy == 0 || doy == 6) {
time = ('08:00');}
else {
time = ('16:30');}
return(time);
}

I think you have to explicitly create the date object first....

sry bout that
leo leo
 
That did it. It was the fact that I wasn't explicitly creating the date object first. Thanks for all your help......
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top