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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to filter date/month in vfp

Status
Not open for further replies.

ivatanakoo

IS-IT--Management
Oct 9, 2014
23
PH
i use the ctod() but it filters only after entering the date
i want to filter the month
need help..tnx
 
What do you mean? What do you want to filter? What do you mean by "filters only after entering the date"? Entering it where?

In general, if you want to filter a table so that you only see records for a given month, you would use the MONTH() function.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Unclear how you use CTOD in conjunction with filter, also unclear how your table is structured and how you enter a date.

To filter something of course you need to specify some value in some condition, yes.

DATE() without parameters gives the current date,, so here parameters are optional, but CTOD() is a conversion function needing a string to convert to a date, without string it'll error with "too few arguments", the function parameter is not optional, you MUST specify a string value, at least CTOD(""), which will be converted to the empty date, not the current date.

Bye, Olaf.

 



....code in my interactive chage combo box...
SELECT issue_table
SET ORDER TO date
thisform.pgfinventory.issuetab.TXT_search.InputMask = "##/##/##"
thisform.pgfinventory.issuetab.txt_search.SetFocus()

....code in interactive change of my search textbox....
IF thisform.pgfinventory.issuetab.cmb_filt.ListIndex=3
set FILTER TO date=CTOD(thisform.pgfinventory.issuetab.txt_search.Value)
thisform.pgfinventory.issuetab.grd_issue.Refresh
GOTO top

when i select the date on the combo box
it displays " / / "
then when search on the textbox
example 10/ /
my grid displays blank..

but when i search 10/04/
then my table is filtered

what i want is when i type the month, it starts to filter..
tnx for your reply...



 
I guess the first problem is this line
IF thisform.pgfinventory.issuetab.cmb_filt.ListIndex=3

The second problem is
CTOD("10")
CTOD("10//")
CTOD("/04/")
CTOD("//14")
CTOD("/04/14")
and CTOD("10//14") retun the empty date.

You can parse the string and use a do case / ICASE()


Respectfully,
Vilhelm-Ion Praisach
Resita, Romania
 
This can't work this ways, as Vilhelm-Ion demonstrates.

You have to put more thought into the filter, if you want to partially filter month only. There is no such thing as a month only date. CTOD is graceful to you, if you at least also provide the day, it assumes the current year, but not so, if only the month is entered. Even if it would, a month always is a date range of 1st to last day. You can't compare a date to a range with =, your filter condition then would need a first and last date and a comparison with >start and <end or use BETWEEN().

And just a side note: That code also very much depends on the date format set to MDY (month first). If your program will run in countries, where dates are DMY or YMD this won't work anyway.

Vilhelm-Ion said:
You can parse the string and use a do case / ICASE()
To expand on this idea, you'd be able to make the filter condition vary depending on how much is already entered. But it will get very messy this way and I'd not recommend that.

Your general condition would need to be something like SET FILTER TO BETWEEN(DATE,THISFORM.startdate,THISFORM.enddate) and you'd need to set THISFORM.startdate and THISFORM.enddate depending on how much is entered into the date textbox. The interactivechange of the textbox could compute the star and enddate.

Bye, Olaf.
 
PS: I hope you know how to add properties to a form. More ideal would actually be user defined properties of such a textbox, but you'd need to create a mycleverdatetextbox class based on textbox and put that into the form. For a starter use the menu Form->New Property to add startdate and enddate properties.

In Interactivechange you can first test, whether CTOD() gives a date. If it's not empty you can set startdate and enddate to that date and filter on this single value. Otherwise take the month number and compute the 1st of the month by Thisform.startdate = DATE(YEAR(DATE(),the month entered,1) and the last of the month by Thisform.enddate = GOMONTH(Thisform.startdate,1)-1.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top