Current Day vs Selected Day

@muneer @tatiang

Hi,

I have an app that adds dates that have been picked by the user to a list however, I was wondering if it was possible to make a condition that states that:

if selected day is 7 days away from current day:
set list item green

if selected day is 3 days away from current day:
set list item red

Would it be possible to change the colour of individual text items in a list viewer depending on the selected dates relation to the current day? Any help you be much appreciated, here is what I have so far:

Link to the project:

https://x.thunkable.com/copy/36b1cc3d181e3d71075fabde4b70bccf

Thanks!

2 Likes

Hi, @jakeheron! I don’t know if checking for a relation between dates is doable, but what I know is we cannot customize font-color/font-size/etc. for specific items in a listviewer.

However, you can try using the DVL (Data Viewer List), and build a custom-layout, and add the label’s text-color in the Advance Bindable Properties. Here’s a demo project - Thunkable

Let me know if this works for you. Cheers!


Also, since this is a public community, please avoid tagging particular people in your first post. :slight_smile:

5 Likes

At the moment this option is not available in the List Viewer

See my demo of how to “highlight a row” in the Data Viewer List
https://x.thunkable.com/projectPage/5fe49968180d0200197113a3

As for date comparison, Thunkable does not provide any specific blocks but what I do is I create an app variable that store the Year followed by the Month and the Day of the date to be compared as text (example 20211026) and multiply it by 1. This gives me a number that I can compare it with another number. If I am comparing two dates then I will convert both dates to numbers using the same formula.

3 Likes

@muneer

Thank you for your help, would it be possible to show some blocks demonstrating this? Thanks.

1 Like

This is a sample block

1 Like

@muneer

Thanks for the sample code. What I would like to occur however is when the user adds an list item with the date, the code adds something to indicate that the task is due soon. This is an example:

So when this screen opens, could there be a code that can parse each assignment, check its due date and add a string to the assignment such as ‘task due soon’'. Here is some pseudocode to explain.

when assignment screen opens:
for each item j in list assignments:
if current day of month - j due date < 4:
set j to join j’s text with ‘task due soon’

hopefully this explains what I would like to occur.

1 Like

@tatiang @kartik14 any help with this would be much appreciated.

1 Like

Your pseudo code is logically correct and you can go ahead implementing it.

Because you parse number of strings in one list entry this will not work directly

You will, instead need the substring that contains the date and parse it again to have all numbers before you can evaluate it.

So for the example above, the date shown in the screen is Oct 29, 2021 you will need to take the last 4 characters then you will need a list of months in 3 letters to convert Oct to 10 and last adding the day of the month to it.

once this is done then you can check if the difference between that date and today is less than 4 days.

Hope this is clear

1 Like

@muneer

I am trying to implement this parsing algorithm you described however, it is much harder than I initially thought. I have successfully managed to parse j to retrieve the year and month. I have used an if statement to convert the month into a number; would there be a better way of doing this to avoid using lots of if statements?

Plus, parsing the day poses a slight problem; the algorithm won’t work for all days since say the first day of the month is ‘1’ and the 20th is ‘20’. These days have different number of characters so I am not sure how I could get the day.

Below is what I have so far:

Thanks!

3 Likes

Hi, @jakeheron! You can try delimiting the date by spaces (using the list from text block in lists section), which would give you a list of Oct | 29, | 2021.

Now since we are splitting by spaces, this won’t have a character count issue. (you can use the get list item #(1/2/3) block to get any of the three items from the delimited list)

image

Let me know if this helps. Cheers!

1 Like

@kartik14

Thank you for your ingenious solution. I have tried to make an algorithm using this premise:

There is one slight problem. When the list is created using a delimiter, each list item is essentially each letter from the string, not the individual date components. For instance, if the date is Oct 29, 2021, the least created is O, c, t, 29, 2, etc. Is there a way to work around this? Here is a link to the project. Go to the ‘Homework’ screen to see the code.

https://x.thunkable.com/copy/79a3c0d5a974681e10ae278ad1abe150

Thanks!

2 Likes

Hi, @jakeheron - I’m glad it worked. Nice work! :clap:

I had a look into your project, and found out that you are trying to delimit the text by 2 spaces , instead of one. I think entering a single space should do the job.

image

Let me know if it works. Cheers!

1 Like

@kartik14 I have added this however, the issue persists. Plus I found another possible issue. The code makes a list from the sub string of j as so:

However, since the length of the string will change depending if the day is one or two digits, it won’t work. Any way of working around this?

Thanks!

1 Like

@jakeheron

TBH I am a bit confused - can you please clarify more on why are you trying to substring the variable j? Is it to get the date? Thanks!

1 Like

@kartik14

No problem:

Here you can see that there is a list ‘stored variable assignments’ that contains all of the user inputed tasks. For each item ‘j’ in that list, ‘app variable assignment due date’ is being set as the substring of ‘j’ containing the date. This date is later parsed again to separate all of the date components: day, month, year.

The problem here is that the parsing won’t work as the number of characters within the date substring will change depending on the day. Therefore, this algorithm will only work with days containing two digits eg. 29.

Does that help?

1 Like

This shows you apply different date formats within your app which will make it difficult to extract
image
The image is from your earlier post.

Anyway, let us assume you will standardize it on Oct 29,2021 format

If I would take the first entry in your list "Mathematics: Oct 29, 2021 Do this then I will do the following
(I will use more variables that I would normally do for clarification)

Setting up variables

Process the entry to get the date and reformat it


Sample output displaying the entry
image

Resulting date after processing
image

Hope this is clear enough to get you back in the track.

2 Likes

Thank you so much @muneer for taking the time to design this code. I have tried to implement your solution but using a for loop to check each item, j, within an assignment list. I added one assignment to the list and made it so a label would display the date. The result was that the date displayed was a weird mess of the list item, bearing no resemblance to the date you got in your testing. I have carefully checked for errors but I couldn’t spot the issue so i’ve included the code:

Variables:

Algorithm:

Just for reference, this is the date I am getting when I try and display the date from the earlier example:

Screen Shot 2564-10-28 at 18.49.40

Thanks!

2 Likes

I can see where you got wrong.
The algorithm is to extract the date from the assignment and then use the date extracted to split it further in year, month and day but when you coded your blocks you continued using “j” where you should use “assignment date”.

See the circles around wrong variables in your code
image

1 Like

Thank you @muneer , the parsing algorithm is working perfectly now. The last small thing is creating a condition that labels tasks due soon. I have had a go at implementing this:

However, the if statement seems to be returning true no matter what date I select. Additionally, the ‘Assignment due soon’ message keeps getting duplicated when the screen opens.

1 Like

The image is not showing in the post.