From: Stefan L on
Hi,

I Have 2 posts in a database with the field "NYKALDAT" (date)
containing
Post 1 = 2010-05-17
Post 2 = 2010-04-08

// Visual Objects (Version 2.8. Build 2.2828), Version 2.8 SP2

Now I try to filter the database like this:
? DTOC(Today()) // Gives "2010-04-28"
? cFilter := "NYKALDAT" + " < " + DTOC(Today()) // Gives "NYKALDAT <
2010-04-28"
uCB := &("{||" + cFilter + "}") // Codeblock
? SELF:oSFSub_Form1:Server:SetFilter(uCB ,cFilter) // Gives .T.
SELF:oSFSub_Form1:Server:GoTop()

DO WHILE !SELF:oSFSub_Form1:Server:EOF
? SELF:oSFSub_Form1:Server:Recno // No records! Should show Post
2.
SELF:oSFSub_Form1:Server:Skip()
ENDDO

Now I try to change the date format like this:
cDate := GetDateFormat()
SetDateFormat("MM.DD.YYYY")

? DTOC(Today()) // Gives "04.28.2010"
? cFilter := "NYKALDAT" + " < " + DTOC(Today()) // Gives "NYKALDAT <
04.28.2010"
uCB := &("{||" + cFilter + "}") // Codeblock
? SELF:oSFSub_Form1:Server:SetFilter(uCB ,cFilter) // Gives .T.
SELF:oSFSub_Form1:Server:GoTop()

DO WHILE !SELF:oSFSub_Form1:Server:EOF
? SELF:oSFSub_Form1:Server:Recno // Show both records! Should only
show Post 2.
SELF:oSFSub_Form1:Server:Skip()
ENDDO

Can somebody enlighten me? If I test with a numeric field it works.

Stefan L
From: Stephen Quinn on
Stefan

Try
cFilter := "NYKALDAT" + " < CTOD( '" + DTOC(Today()) + "' )"
// Gives "NYKALDAT < CTOD( '2010-04-28' )"

The formatted date ('2010-04-28') is for visual purposes only, you have to
convert it back for comparisons.

CYA
Steve


From: Stefan L on
On 28 Apr, 02:24, "Stephen Quinn" <stevej...(a)bigpondSPAM.net.au>
wrote:
> Stefan
>
> Try
> cFilter := "NYKALDAT" + " < CTOD( '" +  DTOC(Today()) + "' )"
>     // Gives "NYKALDAT < CTOD( '2010-04-28' )"
>
> The formatted date ('2010-04-28') is for visual purposes only, you have to
> convert it back for comparisons.
>
> CYA
> Steve

Thanks Stephen,
Worked like a charm.
Stefan
From: John Martens on
Dtos() could also help.


Op 28-4-2010 1:09, Stefan L schreef:
> Hi,
>
> I Have 2 posts in a database with the field "NYKALDAT" (date)
> containing
> Post 1 = 2010-05-17
> Post 2 = 2010-04-08
>
> // Visual Objects (Version 2.8. Build 2.2828), Version 2.8 SP2
>
> Now I try to filter the database like this:
> ? DTOC(Today()) // Gives "2010-04-28"
> ? cFilter := "NYKALDAT" + "< " + DTOC(Today()) // Gives "NYKALDAT<
> 2010-04-28"
> uCB :=&("{||" + cFilter + "}") // Codeblock
> ? SELF:oSFSub_Form1:Server:SetFilter(uCB ,cFilter) // Gives .T.
> SELF:oSFSub_Form1:Server:GoTop()
>
> DO WHILE !SELF:oSFSub_Form1:Server:EOF
> ? SELF:oSFSub_Form1:Server:Recno // No records! Should show Post
> 2.
> SELF:oSFSub_Form1:Server:Skip()
> ENDDO
>
> Now I try to change the date format like this:
> cDate := GetDateFormat()
> SetDateFormat("MM.DD.YYYY")
>
> ? DTOC(Today()) // Gives "04.28.2010"
> ? cFilter := "NYKALDAT" + "< " + DTOC(Today()) // Gives "NYKALDAT<
> 04.28.2010"
> uCB :=&("{||" + cFilter + "}") // Codeblock
> ? SELF:oSFSub_Form1:Server:SetFilter(uCB ,cFilter) // Gives .T.
> SELF:oSFSub_Form1:Server:GoTop()
>
> DO WHILE !SELF:oSFSub_Form1:Server:EOF
> ? SELF:oSFSub_Form1:Server:Recno // Show both records! Should only
> show Post 2.
> SELF:oSFSub_Form1:Server:Skip()
> ENDDO
>
> Can somebody enlighten me? If I test with a numeric field it works.
>
> Stefan L