Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Donate Today!

Do you enjoy these
technical forums?
Donate Today! Click Here

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Stevo123 (IS/IT--Management) (OP)
10 May 12 14:42

Hi All,

I'm fairly new to VFP and am trying to use the SET FILTER TO command to filter on a date in a table but I get a syntax error when doing the following:

SET FILTER TO datepaid = "05/07/12"

How can I filter on just a single date?

Thanks

Steve

MikeLewis (Programmer)
10 May 12 15:27

If the Datepaid field is a Date data type (which it probably is), then you need to do this:

CODE -->

SET FILTER TO DATE(2012, 7, 5)

This will set the filter to 5 May 2012.

The problem with your code is that you are comparing a date to a character string, which doesn't work in VFP (unlike some other languages).

Hope this helps.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy

TamarGranor (Programmer)
10 May 12 16:18

Just to add to Mike's comments, SET FILTER isn't usually the best way to do things. Depending on your goal, different approaches are better.

So what are you actually trying to do here?

Tamar

Stevo123 (IS/IT--Management) (OP)
10 May 12 17:03

Thanks for your replies!

I'm trying to troubleshoot some data in a table (payments table) that has a record of payments made to a loan. The datepaid field is obviously the date the payment was entered (and is a date field in VFP), so I was trying to browse the table with a filter set to the date I was troubleshooting.

Is this the right approach?

Steve

jrbbldr (Programmer)
10 May 12 18:06

You have already been given good advice for setting a FILTER

But first you have to determine the field type of the data.
If it is a Date, then with what you have above you should be good-to-go.

But if it merely Looks like a Date, but is, in reality, something else (e.g. Character, DateTime, etc.), then changes would need to be made.

Until you tell us differently, I'll assume that it really is a Date field type.

Another way to get just the desired records would be to use a SQL Query to acquire only those records matching your criteria

CODE -->

cDateToFind = "05/07/12" && Criteria in String Format
SELECT *;
FROM MyTable;
WHERE Date = CTOD(cDateToFind);
INTO CURSOR Results READWRITE

Note - In VFP there are a variety of ways to represent a Date value
dDate = {^2012-5-7}
?TYPE('dDate')
dDate = DATE(2012,5,7)
?TYPE('dDate')
dDate = CTOD("5/7/2012")
?TYPE('dDate')

Good Luck,
JRB-Bldr

MikeLewis (Programmer)
11 May 12 3:30

Steve,

I would normally agree with the advice to avoid using SET FILTER. Within an application, there are better ways of achieving your goal.

However, since you are only interested in browsing the data yourself in order to locate a problem, it's perfectly acceptable to use SET FILTER. In fact, in this particular case, it's probably the simplest way to do it.

Since we've now established that the field is a Date data type, the code I gave you (in the second post, above) is all you need.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy

OlafDoschke (Programmer)
11 May 12 3:44

Mike,

almost, because SET FILTER TO DATE(y,m,d) will not work, you need SET FILTER TO datefield = DATE(y,m,d)

I'd use BROWSE FOR datefield = DATE(y,m,d) in this case The advantage is, once you edit the date, it will not match the filter and seem to vanish, if you BROWSE FOR a condition, you will see all reacords you get initially, even if editing them in a way that removes them from that condition.

Bye, Olaf.

MikeLewis (Programmer)
11 May 12 4:04

My mistake. I should have said this:

CODE

SET FILTER TO DatePaid = DATE(2012, 7, 5)

Thanks for pointing that out, Olaf. Also I take your point about editing the date, although I don't suppose that will matter in this case.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy

TamarGranor (Programmer)
11 May 12 16:22
Just wanted to add that I agree with Mike. For interactive use, SET FILTER is fine. I just wouldn't use it in an application.

Tamar
Stevo123 (IS/IT--Management) (OP)
11 May 12 17:38
Thanks very much everyone. I'm glad I've found this forum! Appreciate the fast and useful help!
MikeLewis (Programmer)
13 May 12 7:47
Now that you've found us, be sure to come back when you have more questions.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close