Datagrid and dates

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
CAsba
Posts: 364
Joined: Fri Sep 30, 2022 12:11 pm

Datagrid and dates

Post by CAsba » Mon Oct 30, 2023 12:10 pm

Hi,
Here is, I think, an interesting coding problem.
There is a column in the DG that holds the date when the customer of that row must respond to generated question; LC flags up when the date is the same as the long system date. So far, so easy...

Code: Select all

 if the dgtext of grp "Datagrid 1" of cd "custlist" contains the long system date then.....
The problem is that on that particular day it is possible that the user did not use the computer, so, on subsequent days, no generated question will be generated - the 'opportunity' will have been missed.
The code, then, needs to include the possibility that the day was missed by ...(in psuedo code)

if the dgtext of grp "Datagrid 1" of cd "custlist" contains the long system date or the dgtext of grp "Datagrid 1" of cd "custlist" contains a long date before the long system date

Any ideas ?

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Datagrid and dates

Post by Klaus » Mon Oct 30, 2023 12:25 pm

Hi CAsba,

Code: Select all

...
put the dgtext of grp "Datagrid 1" of cd "custlist" into tDGText
put the long system date into tLSD

## In the end tYesterday will contain the long system date of, you guessed, yesterday :-)
put tLSD into tYesterday

## Read up DATEITEMS in the dictionary, very handy for manupulating dates!
convert tYesterday from long system date to dateitems
subtract 1 from item 3 of tYesterday
convert tYesterday from dateitems to long system date

## Now check your dgtext:
 if (tDGText contains tLSD) OR (tDGText contains tYesterday) then...
Best

Klaus

CAsba
Posts: 364
Joined: Fri Sep 30, 2022 12:11 pm

Re: Datagrid and dates

Post by CAsba » Mon Oct 30, 2023 12:33 pm

Hi Klaus,
Thanks for that

BUT

That would work if the user had missed one day, but what if he had missed 2 days, or a week, or a month?

I think what is required is to specify a date prior to the current date, or less than the current date in seconds maybe ??

Best regards,

CAsba

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Datagrid and dates

Post by Klaus » Mon Oct 30, 2023 1:54 pm

Sorry, I misunderstood your problem.
OK this will require a more elaborate scripting, since "if tDGText contains..." does not work.
You will need a repeat loop.

Do this:

Code: Select all

...
## We only need the dateitems, so no LONG date neccessary
put the date into tDate
convert tDate to dateitems

## Presumed you need the date from 3 days ago:
set itemdel to ","
subtract 3 from item 3 of tDate

## We need the seconds for comparison:
convert tDate from dateitems to seconds

put the dgtext of grp "Datagrid 1" of cd "custlist" into tDGText

## Now do the comparison for each line in the datagrid
## Presumed your column with the long date = 4
set itemdel to TAB
put false into tOlderDate
repeat for each line tLine in tDGText
  put item 4 of tLine into tDate2
  convert tDate2 from long system date to seconds
  
  ## !! Compare now:
  if tDate2 <= tDate then
     put TRUE into tOlderDate
     exit repeat
  end if
end repeat

if tOlderDate = TRUE then
  ## Do your thing now
...
Out of my head, but should work :-D

Best

Klaus

CAsba
Posts: 364
Joined: Fri Sep 30, 2022 12:11 pm

Re: Datagrid and dates

Post by CAsba » Tue Oct 31, 2023 1:52 pm

Hi Klaus,
Great, it worked fine. After some fiddling around I put the repeat inside another repeat, so it picks up and actions all the customers whose review date is in the past.
Many thanks, once again, for your valued knowledge.

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Datagrid and dates

Post by Klaus » Tue Oct 31, 2023 2:06 pm

My pleasure!

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”