Getting current week

Results 1 to 4 of 4

Thread: Getting current week

  1. #1
    Alex T. Guest

    Default Getting current week

    Hi. I am trying to get task information out of the database (SQL Server) using the current week. Basically, I want to display all the tasks for the current week. Here is the SQL that I am using. Can anyone help with this?<BR><BR>SQL="SELECT * from tblTasks where TaskDate= &#039;" & (DatePart("ww", Now)) & "&#039;"

  2. #2
    Alext T. Guest

    Default Nevermind..I am an idiot

    FYI: I just need to remove the apostrophes

  3. #3
    Alex T. Guest

    Default Actually, I do need help now

    Okay, now I keep getting a Type Mismatch Error. I just want to select all the taks frm the database that are for the current week.<BR><BR>Here is my code:<BR><BR>Dim DateVar<BR>DateVar = DatePart("ww", Now)<BR>SQL="SELECT * from tblTasks where &#039;" & DateVar & "&#039; = &#039;" & (DatePart("ww", "TaskDate")) & "&#039;"

  4. #4
    Join Date
    Dec 1969

    Default Makes no sense...

    A WHERE clause that is not based on some field in the given table becomes, essentially, a "SELECT ALL" or "SELECT NONE" query, depending on the truth of the clause.<BR><BR>If you do a RESPONSE.WRITE of your SQL, you&#039;ll see something like this (assuming you can get that far...probably not):<BR><BR>SELECT * from tblTasks where &#039;17&#039; = &#039;&#039;<BR><BR>Because, of course, when you do that second DatePart function you are asking it to find the week number of a string ("TaskDate") and DatePart is choking.<BR><BR>So you have several mistakes:<BR><BR>(1) DatePart returns a *number*, not a string, so you certainly don&#039;t want to put the value it returns in &#039;...&#039; marks! <BR><BR>(2) DatePart is a valid function in both VBS (and you use it correctly to get the week number of Now) *and* in Access (and in TSQL, though then the syntax is a little different). <BR><BR>(3) *BUT* if you will use DatePart in Access, then it needs to be part of the Access expression, *not* something you try to import from VBS.<BR><BR>(4) In Access, you need to use &#039;ww&#039; instead of "ww".<BR><BR>(5) In *no* version of DatePart do you want to put quotes around a variable name! In both VBS *and* Access, putting quotes around something means "take this AS IS as a string and don&#039;t muck with it at all any more". <BR><BR>So...<BR><BR>Dim DateVar<BR>DateVar = DatePart("ww", Now)<BR>SQL="SELECT * from tblTasks where " & DateVar & " = DatePart(&#039;ww&#039;, TaskDate)"<BR><BR>Ehhh??<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts