I feel like this should be a really straight forwards process, but for the life of me, I can't work out how to get it done! Arrays!!!
Ok, I have a database of accounts (SQL), that I am loading into a livecode file and displaying in a datagrid. I have scripted all of the SQL search, change, write, etc. functions and they are working well. The data looks a little like this:
ID Date Name Paid Notes
1 31/1/2020 John Blog $12.00 Nil
2 25/2/2020 Jane Blog $15.00 Nil
...
THEN... I decide I need to report a date segment (financial year, etc.), and I search my SQL, only to find that, even though the "Date" column is formatted for Dates, the actual data doesn't fit the SQL format of YYYY-MM-DD (it's not DD/MM/YYYY, like a normal human!) So, I can't search the SQL to get into the datagrid to show me the report.
Grrr...
So now I am going through to change the date format so it can be recognised by SQL. Easy... but I have 3 years of accounts, and way too many to bother doing by hand 1 by 1.
What I essentially need to do is this:
Search all entries in SQL (can do, easy as)
Display all entries in Datagrid on screen (can do.)
Go through each item of the 'Date' column and reorganise the items and change the delimiters. (maybe... and where I am getting stuck.)
Here's my thoughts:
Code a temporary button that does this:
Code: Select all
on mouseup
put the dgdata of group "Accounts" into theDataA --put into array
repeat for each element of theDataA["Date"]
set the item delimiter to "/"
put item 3 of ??? &"-"& item 2 of ??? &"-"& item 1 of ??? into NewDate --not sure what to reference here! Item 1 of which element?
put newDate into ??? --not sure where to put it once I have it!
end repeat
--put this back into the datagrid "accounts"
end mouseup
Is this the way to do it? Is there an easier way, or am I just over-complicating it? Should I just do it in the SQL? Can I do it in the datagrid, or do I need to go through the array to change it?
Thanks in advance!
X