Solved! Go to Solution.
??? DATEADD(year, " + dblYears + "," + strFromDate + ")
That's in your where clause and I think that should be SQL, so I'm not sure that makes sense. Shouldn't it be similar to VBScript?, where the syntax is the following where the interval is essentially day, month, year, etc and the number is a long integer val, and date is a literal?:
DateAdd(interval, number, date)
This may help:
http://www.pressthered.com/adding_dates_and_times_in_python/
I still don't get it -- bear with me for a moment... I may be wrong but this is worth taking a look at (and I still think your DATEADD statement is in error). Can you fill me in on what the '+' symbols are referring to in your posted strWhere statement?-
DATEADD(year, " + dblYears + "," + strFromDate + ")
>>> x(str(01012006), str(0.0)) "qryELM.elmPK = tblELM.elmPK AND dbo.tblELM.LoggedDate >= '7270-26-' AND dbo.tblELM.EnquiryFK IN (4,22,25,61)" >>> >>> str(01012006) '267270' >>>
>>> x(str(01012006), str(0.0)) "qryELM.elmPK = tblELM.elmPK AND dbo.tblELM.LoggedDate >= '7270-26-' AND dbo.tblELM.EnquiryFK IN (4,22,25,61)" >>> >>> str(01012006) '267270' >>>
>>> import time >>> def x(Start_Date): strFromDate = time.strftime("%Y-%d-%m", Start_Date) strWhere = "qryELM.elmPK = tblELM.elmPK AND dbo.tblELM.LoggedDate >= '" + strFromDate + "' AND dbo.tblELM.EnquiryFK IN (4,22,25,61)" return strWhere
>>> # Your 1st date as 3 variables, type integer: >>> day, mon, year = 1, 1, 2001 >>> print day, mon, year 1 1 2006 >>> # converted to 'concatenated' space-delimited string: >>> strDate = '{0} {1} {2}'.format(day, mon, year) >>> print strDate 1 1 2006 >>> # the string converted to time.struct obj >>> objYourDate1 = time.strptime(strDate, '%d %m %Y') >>> print objYourDate1 time.struct_time(tm_year=2006, tm_mon=1, tm_mday=1, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=6, tm_yday=1, tm_isdst=-1) >>> # Your 2nd date as 3 variables, integer, etc. etc. (no further comments necessary): >>> day, mon, year = 31, 5, 2001 >>> print day, mon, year 31 5 2001 >>> strDate = '{0} {1} {2}'.format(day, mon, year) >>> print strDate 31 5 2001 >>> objYourDate2 = time.strptime(strDate, '%d %m %Y') >>> print objYourDate2 time.struct_time(tm_year=2001, tm_mon=5, tm_mday=31, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=3, tm_yday=151, tm_isdst=-1)
>>> x(objYourDate1) "qryELM.elmPK = tblELM.elmPK AND dbo.tblELM.LoggedDate >= '2006-01-01' AND dbo.tblELM.EnquiryFK IN (4,22,25,61)" >>> x(objYourDate2) "qryELM.elmPK = tblELM.elmPK AND dbo.tblELM.LoggedDate >= '2001-31-05' AND dbo.tblELM.EnquiryFK IN (4,22,25,61)"