ASP - Datepart function - Asked By Susan Cantrell on 19-Jul-14 02:21 AM

I am trying to pull information out of a SQL Server 7.0 table based on the date.  I want to only pull information that is greater than or equal to today's date minus 6 months.  I am able to subtract 6 from month(date()), but today's date gives me December, therefore I end up with 12/4/2001.  That's my problem, I need to subtract 1 from year(date()) if month(testdate) > month(date()).  I need to end up with the value of my variable being 12/4/2000.  I am using VB Script to create my variable then pulling the data from the table.
Here is the code I am currently trying to make work for me...

test = date()
testmonth = month(test) - 6
testd = month(testmonth) & "/" & day(test) & "/" & year(test)

If month(testd) > month(test) then
testyear = year(testd) - 1
End if
testdate = month(testd) & "/" & day(testd) & "/" & year(testyear)
response.write testdate

Any help would be greatly appreciated...

I made two small corrections... - Asked By Robbe Morris on 04-Jun-01 02:15 PM

...Testdate should show the proper date now.

test = date() 

testmonth = month(test) - 6 

testd = month(testmonth) & "/" & day(test) & "/" & year(test) 

testyear = year(testd) 

If month(testd) > month(test) then 
testyear = year(testd) - 1 
End if 

testdate = month(testd) & "/" & day(testd) & "/" & testyear 

response.write test & "<br>"
response.write testd & "<br>"
response.write testdate  & "<br>"

Thanks! - Asked By Susan Cantrell on 19-Jul-14 02:21 AM

Thanks!  That works perfectly!

Sure thing...Take care. - Asked By Robbe Morris on 04-Jun-01 02:23 PM

...
Using DateAdd function of ASP - Asked By Adhik Kadam on 19-Jul-14 02:22 AM
Yes know solution but that is again calculated. here i m giving u one function that might u know but it works perfact
coz i have used it at many place in projects.....

In ASP a fucntion is DateAdd(Interval,Number,Date)

Here interval is given contants for function for u it is "m"
interval = "m"
Number is = "-6"
Date = Date()

In this DateAdd if u add -6 months it gives u date of exact 6 month back
 
bye just try it out.....
She already has that in her code... - Asked By Robbe Morris on 27-Jun-01 08:19 AM
...She needed to do something special with the year depending on where she was at with the month.  Her issue wasn't substracting the month it was calculating what year she would be in.

I think her solution will out ok with my small adjustments