Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

date not working

Status
Not open for further replies.

vlitim

Programmer
Sep 2, 2000
393
GB
I am using the below code, so that an item is only displayed if completed within the last month. But it doesn't work, no errors are shown but the dates older than a month still show up. Can anyone shed some light on this!?

datenow = DateAdd("m", -1, Date)
sqlString = "active=1 And completedDate >= " & datenow & ""

Cheers
Tim
 
The code is just ok but...
If u are using ACESS as database
use
datenow = DateAdd("m", -1, Date)
sqlString = "active=1 And completedDate >= #" & datenow & "#"
SQL database
use
datenow = DateAdd("m", -1, Date)
sqlString = "active=1 And completedDate >= '" & datenow & "'"
________
George, M
 
I am using SQL and tried your suggestion but still it has no effect on the results for some reason
 
Have u print the datenow value to see if it's ok?
________
George, M
 
U need to check your final querry stored in sqlString in Querry Analizer to see if works...
select * ... and active=1 And completedDate >= '08/01/2001'
________
George, M
 
I've had the best luck with comparing dates when I use the BETWEEN operator. Try something like:
[tt]
WHERE Active<>0
AND completedDate BETWEEN '31-Dec-1899' AND datenow
[/tt]

Chip H.

BTW: I changed your test for the Active flag to &quot;<> 0&quot;, rather than checking for it to be equal to 1. In all lnguages I'm aware of, FALSE is always 0. But in many languages the &quot;TRUE&quot; condition is defined as being &quot;NOT FALSE&quot;, which could mean that True is a positive 1, or maybe a negative one, or even a MAX_INT. By checking for a non-zero, you'll never have to worry about being tripped up by it.

 
Thanks for all the help have managed to figure it out now, its was the SQL date setting was different to what I was comparing against
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top