# Current Day vs Selected Day

**URL:** <https://community.thunkable.com/t/current-day-vs-selected-day/1581333>\
**Category:** Questions about Thunkable X\
**Created:** [October 26, 2021, 6:18am UTC](https://community.thunkable.com/t/current-day-vs-selected-day/1581333 "2021-10-26T06:18:55Z")\
**Posts on this page:** 20\
**Page:** 3

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [October 30, 2021, 4:24pm UTC](https://community.thunkable.com/t/current-day-vs-selected-day/1581333/41 "2021-10-30T16:24:21Z")

</div>

Use these blocks to read/write values in the sheet  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/a/9/a9b223fe6278fe37deb8c547504bc1462630ad80.png)  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/5/6/56f0d9a2d2acf959833705294d6f364d70b57322.png)

The result column has this formula `=K2 - J2`  
The `start date` column and the `end date` column need to be formatted as **DATES** for the formula to work.

---

<div class="post-metadata">

**Author:** ![jakeheron](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jakeheron/32/116818_2.png) [@jakeheron](https://community.thunkable.com/u/jakeheron)\
**Post date:** [October 30, 2021, 4:28pm UTC](https://community.thunkable.com/t/current-day-vs-selected-day/1581333/42 "2021-10-30T16:28:20Z")

</div>

Forgive me but I am slightly confused. I understand that Google sheets can read the dates and determine their difference. However, how would we put the dates there? Won’t there just be rows and rows of dates that would be inserted every time the screen opens?

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [October 30, 2021, 4:31pm UTC](https://community.thunkable.com/t/current-day-vs-selected-day/1581333/43 "2021-10-30T16:31:31Z")

</div>

If you see the block I shared, it says `update value`. You need this just to get the difference of the selected assignment so you will have **one single row in this sheet**.

Whenever you want to check the difference between any dats, you will update column `start date` and column `end date` with your two dates and you will read the difference in days from the third column.

---

<div class="post-metadata">

**Author:** ![jakeheron](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jakeheron/32/116818_2.png) [@jakeheron](https://community.thunkable.com/u/jakeheron)\
**Post date:** [October 30, 2021, 4:32pm UTC](https://community.thunkable.com/t/current-day-vs-selected-day/1581333/44 "2021-10-30T16:32:42Z")

</div>

@muneer alright thank you, I will try implementing this. I will let you know if I am successful or not.

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [October 30, 2021, 4:42pm UTC](https://community.thunkable.com/t/current-day-vs-selected-day/1581333/45 "2021-10-30T16:42:41Z")

</div>

If you don’t like the Google sheet approach then let me know to adjust the procedures we built together for the date functions and make if work the expected way.

---

<div class="post-metadata">

**Author:** ![jakeheron](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jakeheron/32/116818_2.png) [@jakeheron](https://community.thunkable.com/u/jakeheron)\
**Post date:** [October 30, 2021, 4:46pm UTC](https://community.thunkable.com/t/current-day-vs-selected-day/1581333/46 "2021-10-30T16:46:43Z")

</div>

@muneer Personally, I would prefer the first approach if you do not mind. I would like to keep things as local as possible in terms of data manipulation which why I have for the most part not used external data sources. The Google Sheets are always an option however. But trying to adjust the previous code would be more preferable for me if you do not mind. Thanks.

---

<div class="post-metadata">

**Author:** ![jakeheron](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jakeheron/32/116818_2.png) [@jakeheron](https://community.thunkable.com/u/jakeheron)\
**Post date:** [October 30, 2021, 5:21pm UTC](https://community.thunkable.com/t/current-day-vs-selected-day/1581333/47 "2021-10-30T17:21:26Z")

</div>

@muneer I was thinking for simplicity, I could change the date format to MM/DD/YYYY. Would that help in any way with comparing dates?

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [October 30, 2021, 5:56pm UTC](https://community.thunkable.com/t/current-day-vs-selected-day/1581333/48 "2021-10-30T17:56:05Z")

</div>

I redesigned the function we did together.

After getting the date as YYYYMMDD we need to do the following

Supporting variables and functions

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/8/9/89bbb2d91460b74e4b5ceac01369c4224178b881.png)

Main function

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/d/c/dc5542d8aac35efbc5e0d31963f31719f788ca1a.png)

This is how you call it

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/5/3/53807aeabfa4d828cd21fc38baf2300de3a28fb4.png)

Sample result  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/f/d/fde3da1970f149f6f92d7dc244033a309f81472b.png)

This gives the number of days since beginning of the year in addition to the year value. It will computer the number of days correctly.

You can check using this calendar  
[https://www.calendar-365.com/day-numbers/2021.html](https://www.calendar-365.com/day-numbers/2021.html)

---

<div class="post-metadata">

**Author:** ![jakeheron](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jakeheron/32/116818_2.png) [@jakeheron](https://community.thunkable.com/u/jakeheron)\
**Post date:** [October 31, 2021, 3:38am UTC](https://community.thunkable.com/t/current-day-vs-selected-day/1581333/49 "2021-10-31T03:38:52Z")

</div>

Thank you so much @muneer , there is a couple of things I have noticed however.

> [@muneer](#):
>
> Supporting variables and functions
> 
> ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/8/9/89bbb2d91460b74e4b5ceac01369c4224178b881.png)

In these supporting variables `app variable monthCounter` as well as `app variable yearCounter` are not used in your given functions. Are they still necessary? Whats more is that there are the variables `inputYear` , `inputMonth` and `inputDay` which I do not see initialised. Are these the dates components of each date that has been parsed from the assignment?

> [@muneer](#):
>
> This is how you call it
> 
> ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/5/3/53807aeabfa4d828cd21fc38baf2300de3a28fb4.png)

I also don’t currently see an option to pass variables into a function as you have done here. Is this possibly a discrepancy between StP and DaD? If so, how can I get around this?

Thanks!

---

<div class="post-metadata">

**Author:** ![jakeheron](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jakeheron/32/116818_2.png) [@jakeheron](https://community.thunkable.com/u/jakeheron)\
**Post date:** [October 31, 2021, 3:42am UTC](https://community.thunkable.com/t/current-day-vs-selected-day/1581333/50 "2021-10-31T03:42:46Z")

</div>

Edit:

I have found out how to pass in variables:

![Screen Shot 2564-10-31 at 10.42.39](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/2/3/2357e5de9f1f33e8aa9855b91c9cfa5cd89d751f.png)

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [October 31, 2021, 3:46am UTC](https://community.thunkable.com/t/current-day-vs-selected-day/1581333/51 "2021-10-31T03:46:03Z")

</div>

> [@jakeheron](#):
>
> are not used in your given functions

That’s ok, you don’t need to use them. I’m using them for another task which converting `seconds since 1970` to a proper date. This is not required for your function.

When you add a function to your code, you can use the `gear icon` in the function block to add parameters. Those will show in the `variables` drawer but will be differentiated by having the name only without the proceeding `app variable` or similar.

---

<div class="post-metadata">

**Author:** ![jakeheron](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jakeheron/32/116818_2.png) [@jakeheron](https://community.thunkable.com/u/jakeheron)\
**Post date:** [October 31, 2021, 4:05am UTC](https://community.thunkable.com/t/current-day-vs-selected-day/1581333/52 "2021-10-31T04:05:54Z")

</div>

Thanks @muneer . To confirm, `thisMonth = current month` correct?

Also, where is `thisMonth` being initialised?

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [October 31, 2021, 7:29am UTC](https://community.thunkable.com/t/current-day-vs-selected-day/1581333/53 "2021-10-31T07:29:04Z")

</div>

> [@jakeheron](#):
>
> `thisMonth = current month`

No sir, it isn’t.

thisMonth is a running counter for the loop and not to be used outside of the loop block. It requires no initialization.

---

<div class="post-metadata">

**Author:** ![jakeheron](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jakeheron/32/116818_2.png) [@jakeheron](https://community.thunkable.com/u/jakeheron)\
**Post date:** [October 31, 2021, 8:25am UTC](https://community.thunkable.com/t/current-day-vs-selected-day/1581333/54 "2021-10-31T08:25:26Z")

</div>

@muneer I see but if it needs no initialisation, where is the variable made? Is it a parameter to another function because I can see it in any other function in the code you supplied?

Thanks!

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [October 31, 2021, 8:52am UTC](https://community.thunkable.com/t/current-day-vs-selected-day/1581333/55 "2021-10-31T08:52:40Z")

</div>

When you add a looping block such as the count block I used in this example, you will have a default variable **i**. You can click on it and notice the option before last in the pop-up menu **Rename variable…**

![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/3/1/3159db6adc7f493dc90d563819f67e3704751c63.png)  
click on the option and you should see a dialog box to input the new variable name. Enter your new variable to replace the default **i**.  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/f/7/f72a471484016846e6317517dd468a16d6ff7846.png)  
Click OK and now you should see your new variable in the looping block.  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/9/3/934c8eec163d0cce73d72cbad9dfa407a5dab39c.png)

Hope this clarifies the issue.

---

<div class="post-metadata">

**Author:** ![jakeheron](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jakeheron/32/116818_2.png) [@jakeheron](https://community.thunkable.com/u/jakeheron)\
**Post date:** [October 31, 2021, 9:59am UTC](https://community.thunkable.com/t/current-day-vs-selected-day/1581333/56 "2021-10-31T09:59:44Z")

</div>

@muneer thanks. If the variable is simply a running counter, what is the purpose of naming it ‘thisMonth’?

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [October 31, 2021, 10:07am UTC](https://community.thunkable.com/t/current-day-vs-selected-day/1581333/57 "2021-10-31T10:07:14Z")

</div>

> [@jakeheron](#):
>
> If the variable is simply a running counter, what is the purpose of naming it

- Having it as **i** means nothing when you come back to the code again after a while and you loop is not a 2 lines block. Specially if the loop is inside a function with other variables.

- Avoid confusion when you have a loop inside another loop, you want to n  
know which **i** are inserting in your blocks, the one belonging to the inner loop or the one to the outer loop.

- Coding standard that you need to keep to instead of every app has a different way of coding.

Hope this suffices.

---

<div class="post-metadata">

**Author:** ![jakeheron](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jakeheron/32/116818_2.png) [@jakeheron](https://community.thunkable.com/u/jakeheron)\
**Post date:** [October 31, 2021, 10:10am UTC](https://community.thunkable.com/t/current-day-vs-selected-day/1581333/58 "2021-10-31T10:10:22Z")

</div>

Sorry but what does ‘i’ have to do with months? I just asking since I want to fully understand this procedure. I completely understand that it common practice to rename variables to differentiate between loops I am just confused as to what this counting variable has to do with months. Thanks for the explanations @muneer .

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [October 31, 2021, 10:21am UTC](https://community.thunkable.com/t/current-day-vs-selected-day/1581333/59 "2021-10-31T10:21:14Z")

</div>

I needed to total the number of days in the year starting from January to the month entered by the user. I started with a list of number of days in each month and then looped through the number of months till the `inputMonth`

![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/5/3/53f3c9e2c9af00084bdd9931a094e0e77c3f371b.png)  
This is why I renamed the `default i` to `thisMonth`.

You can name it anything you would like or set it back to the default. The name will change nothing as long as you add up every number of days in the month from that start of the year till the one just prior to the month of the date being processed.

To get a correct number of days, we need to accumulate the number of days in each month from the start of the year until the month prior to the date we are processing and then add the number of days from the date we are processing.

In my example, I selected 24th October 2021 therefore I need to add up the total number of days from 1st January 2021 until the selected date. I also add the year value so for the example given the number should be 2318.

If you use the same process with any other near date and compare them together you should get the correct number of days which is what you wanted in the first place.

---

<div class="post-metadata">

**Author:** ![jakeheron](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jakeheron/32/116818_2.png) [@jakeheron](https://community.thunkable.com/u/jakeheron)\
**Post date:** [October 31, 2021, 10:26am UTC](https://community.thunkable.com/t/current-day-vs-selected-day/1581333/60 "2021-10-31T10:26:12Z")

</div>

Thanks @muneer , this clears things up a lot. I will try and implement the procedures and will report back my results.

[Previous page](https://community.thunkable.com/t/current-day-vs-selected-day/1581333.md?page=2)

[Next page](https://community.thunkable.com/t/current-day-vs-selected-day/1581333.md?page=4)
