NetTalk Central

Author Topic: Filter on DateTime field  (Read 5525 times)

Niels Larsen

  • Sr. Member
  • ****
  • Posts: 431
    • View Profile
    • Email
Filter on DateTime field
« on: July 10, 2012, 08:28:07 AM »
Hi

I have a table with a DateTime field (mssql). I Clarion i have a group over a string(8) (as I always have when using date and time).
But I have a lot of problems when i want to filter on the time part.

I've tried with the filter on the string and the two fields date / time. It makes no difference - all as hotfields.
Is there anything I should pay particular attention to when I work with time in a filter in NTWS?

Regards Niels

kevin plummer

  • Hero Member
  • *****
  • Posts: 1195
    • View Profile
    • Production Accounting and Software Payroll
Re: Filter on DateTime field
« Reply #1 on: July 10, 2012, 06:03:16 PM »
Can you post your fllter so we can have a look?

Niels Larsen

  • Sr. Member
  • ****
  • Posts: 431
    • View Profile
    • Email
Re: Filter on DateTime field
« Reply #2 on: July 11, 2012, 01:40:43 AM »
Hi Kevin.

I've tried several different ways.

1. filter = 'FIL:Date = LOC:Date AND FIL:Time = LOC:Time'

2. filter = 'FIL:Date = ' & LOC:Date & ' AND FIL:Time = ' & LOC:Time

3. filter = 'FIL:DateTime = LOC:DateTime'
(FIL:DateTime is the string(8) below the DateTimeGroup)

4. filter = 'FIL:DateTime = '& LOC:DateTime

All as hotfields and as not hotfields .

all 4 ways gives filter on the date but not on the time. They all returns all the times for one day.


Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: Filter on DateTime field
« Reply #3 on: July 11, 2012, 01:49:05 AM »
So let's trip out the noise.

>> All as hotfields and as not hotfields .

Hotfields have nothing to do with Filters. I want you and everyone else to internalize this please. Chant it as a mantra over breakfast. Hotfields have nothing to do with filters. Not in Clarion Win32, not in NetTalk, not anywhere.

Hotfields are nothing more or less than adding fields to the View. That's all. Filtered variables do not need to be in the view. Ergo, no connection.

>> 1. filter = 'FIL:Date = LOC:Date AND FIL:Time = LOC:Time'

this kind of filter will not work because you are using a local variable _inside_ the filter string. It's not necessary to do this, and it's just bad.


>> 2. filter = 'FIL:Date = ' & LOC:Date & ' AND FIL:Time = ' & LOC:Time

This to me looks like the best one - assuming that Loc:Date and loc:Time are primed correctly. (Your problem is probably that they're not.)

So using this filter, turn on the option to "Display Filter & Order in Debugview" and paste the actual contents of the filter here. I'm guessing it'll be something like;

FIL:Date =0 AND FIL:Time = 0

Cheers
Bruce



Niels Larsen

  • Sr. Member
  • ****
  • Posts: 431
    • View Profile
    • Email
Re: Filter on DateTime field
« Reply #4 on: July 11, 2012, 05:56:22 AM »
If I use this filter: 'FIL:Dat=' & TODAY() I get all records from today, but only those with the time 0 (DebugView shows FIL:Date = 77262)
If I use this filter: 'FIL:Date='&TODAY()&' AND FIL:Time=3600001' no records shows.(DebugView shows FIL:Date=77262 AND Fil:Time=3600001)

If I remove the filter I can se a lot of records from today (77262) with the time 3600001.

I usually have no problems working with filters, but this I just can't figure out.

/Niels

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: Filter on DateTime field
« Reply #5 on: July 11, 2012, 06:15:01 AM »
I think you are not counting your zeros correctly in 3600001.
I'm suspecting a mismatch between your filter and the data.



Niels Larsen

  • Sr. Member
  • ****
  • Posts: 431
    • View Profile
    • Email
Re: Filter on DateTime field
« Reply #6 on: July 11, 2012, 08:42:11 AM »
No, the values for date and time is right. 10am = 10*60*60*100+1 = 3600001.
If I remove the filter I have lots of records with my filter values.

kevin plummer

  • Hero Member
  • *****
  • Posts: 1195
    • View Profile
    • Production Accounting and Software Payroll
Re: Filter on DateTime field
« Reply #7 on: July 11, 2012, 05:10:36 PM »
try something like

'FIL:Date='&TODAY()&' AND FIL:Time>3600000'

to test Bruce's theory.

I've come across precision problems between SQL and clarion before.

Niels Larsen

  • Sr. Member
  • ****
  • Posts: 431
    • View Profile
    • Email
Re: Filter on DateTime field
« Reply #8 on: July 12, 2012, 06:55:35 AM »
Hi Kevin.

Tried your suggestion but it made no difference.
Then i tried this: 'SQL(A.TIDSPUNKT=''2012-06-28 01:00:00.000'')' ..... and it works great.

I'm still puzzled why I can not filter on the time field. But for now I have to "settle" with the SQL() option.

Thanks for now - over and out.
/Niels