vb6 Using SQL 'Delete From' with a date

Experts please

In a vb6 app which draws data from an Access 2000 database, I want to delete all records that are 7 or more days old. The following deletes all records regardless of date. ActDate is a date/time field

    Dim dCutOff As Date
    dCutOff = DateAdd("d", -7, Date)
    sSQL = "DELETE FROM activity where ActDate" & " < " & "#" & dCutOff & "#;"
    Set rs = cn.Execute(sSQL, , adCmdText)

What's wrong, and what should be done to fix the problem, please

Gordon
Gordon_AtherleyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Éric MoreauSenior .Net ConsultantCommented:
Hi Gordon_Atherley,

Try this
sSQL = "DELETE FROM activity where ActDate < #" & format(dCutOff, "yyyy/mm/dd") & "#;"


Cheers!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DabasCommented:
Hi Gordon_Atherley,
Is your system set to dd/mm/yyyy? In that case, the program might be looking at say, the the 4th of June instead of the 6th of April, causing your problem.

One way to overcome this is to change the following line:

    dCutOff = Format(DateAdd('d',-7,Now), "yyyy-mmm-dd")

Dabas
0
Gordon_AtherleyAuthor Commented:
emoreau and Dabas

You diagnosed the problem and provided effective solutions which differed slightly in approach. Your responses were but 2 minutes apart. Splitting the points seemed the fairest way to go

Thank you both

Gordon
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.