Solved

using datediff function

Posted on 2003-11-11
3
1,330 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

Suggested Solutions

Title # Comments Views Activity
How to show result of a NULL value at random? 33 59
Diminish Pop-up  in 3 seconds 7 70
Code Manager | Snippits 2 65
How to post data to an API using ASP Classic 3 31
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

726 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