Solved

using datediff function

Posted on 2003-11-11
3
1,342 Views
Last Modified: 2008-02-26
Hi,

       I am writing an sql query from within the asp which goes as below:

 strSQL = "SELECT created_date, due_date, "
strSQL = strSQL &  DateDiff("y",created_date,due_date)
strSQL = strSQL & " as leadtime FROM JBSPEC WHERE created_date Between '2003-11-01' And '2003-11-30'"

I can get the records from the created_date and due_date column, but the leadtime column(which is the date difference between due_date and created_date) always give the value 0. Is is something wrong with my query? Appreciate if anybody could help me with this problem.

Thank you.
0
Comment
Question by:elizateh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 9720703
strSQL = strSQL &  DateDiff("yyyy",created_date,due_date)
0
 
LVL 58

Accepted Solution

by:
Gary earned 125 total points
ID: 9720837
Actually what you're trying to do won't work unless you're using MSSQL, you may need to do the calculation after you've got the recordset and are actually needing the leadtime i.e. leadtime=datediff("yyyy",rs("created_date"),rs("due_date"))
0
 
LVL 6

Expert Comment

by:MannSoft
ID: 9723389
You're missing some quotes, so you're calling DateDiff when creating the SQL string instead of making it part of it.  Try:

strSQL = "SELECT created_date, due_date, "
strSQL = strSQL &  "DateDiff(""y"",created_date,due_date) "
strSQL = strSQL & " as leadtime FROM JBSPEC WHERE created_date Between '2003-11-01' And '2003-11-30'"

Now the DateDiff call is actually part of the SQL string (which is why the doubled up quotes are now needed around the Y)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question