Solved

using datediff function

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

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 information …
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/…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

832 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