Solved

using datediff function

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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 …
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now