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
Solved

using datediff function

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

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

791 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