• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2456
  • Last Modified:

How do I select information between 2 dates in delphi access mdb

I have the following SQL
I am adding to delphi codes this query (db is a mdb-access file)

Select SUM(Hours)
From Empolyee
Where (name = 'name') And (date >=#01-06-2008#  and date <= #04-06-2008#)

This query is not turning anything but it is just making the sum for the all data's belong to the name.
So the date selection is not working.

Any idea why?
1 Solution
NayelAuthor Commented:
By the way.

If I do it (date >=#2008/06/01 #  and date <= #2008/06/04#)
then I get the results. But I need to add it from delphi.

sql.add('Select ...')
sql.add('From ....')
sql.add('Where ??????????)
Geert GOracle dbaCommented:
selection from last 7 days :

sql.Add('WHERE date >= :date1 and date <= :date2');
sql.parambyName('date1').AsDateTime := Now - 7;
sql.ParamByName('date2').AsDateTime := Now;

Open in new window

NayelAuthor Commented:

Problem not solved. This will not run in delphi. And my date comes from datetime picker
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Can you give the full select/filter statement.

You should be able to use something like
'date >= ' &  StartDAtePicker.Date & ' and date <= ' & enddatepicker.date

Go into MS Access and build your query in SQL form there. When that works, then go into delphi and build it.
You can do something like this:

s := shortdateformat;
shortdateformat := "aaaa/mm/dd";
sql.add('Select SUM(Hours)')
sql.add('From Empolyee')
sql.add('Where (name = "name") And (date BETWEEN ' + QuotedStr(DateToStr(DateTimePicker1.Date)) + ' and ' + QuotedStr(DateToStr(DateTimePicker2.Date)) + '))';
shortdateformat := s;

Open in new window

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.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now