# Can't get substring of current year

**URL:** https://community.thunkable.com/t/cant-get-substring-of-current-year/1040701
**Category:** Questions about Thunkable X
**Tags:** legacy-interface
**Created:** [December 21, 2020, 5:06pm UTC](https://community.thunkable.com/t/cant-get-substring-of-current-year/1040701 "2020-12-21T17:06:16Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)
#### Post date: [December 21, 2020, 5:06pm UTC](https://community.thunkable.com/t/cant-get-substring-of-current-year/1040701/1 "2020-12-21T17:06:16Z")

</div>

Does anyone know why either of these set of blocks crashes my project (legacy interface)?

 ![Screen Shot 2020-12-21 at 9.05.27 AM](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/0/4/04fb9836098840069cd4df8ad08a38daaa4cdf7f.png)

 ![Screen Shot 2020-12-21 at 9.19.00 AM](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/3/b/3bd5d01252d8a74b14b2323b8c296468962d4d5b.png)

I’m trying to convert 2020 to 20.

Reported at [Getting substring from current year crashes project · Issue #786 · thunkable/thunkable-issues · GitHub](https://github.com/thunkable/thunkable-issues/issues/786).

---

<div class="post-metadata">

### Author: ![domhnallohanlon](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/domhnallohanlon/32/29554_2.png) [@domhnallohanlon](https://community.thunkable.com/u/domhnallohanlon)
#### Post date: [December 21, 2020, 5:44pm UTC](https://community.thunkable.com/t/cant-get-substring-of-current-year/1040701/2 "2020-12-21T17:44:48Z")

</div>

Hey @tatiang - this is a fair assumption, but the “date” type is not the same as a “string” data type. Here’s a quick demo of how to [type cast](https://en.wikipedia.org/wiki/Type_conversion) a date to a string in Thunkable.

The first thing I did was display the date in a label, like you’re doing:

 ![01year](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/5/0/5003e256cc43b2a55a6303318d9dee083bd36b53.png)

Next, I tried to pass the year object to a sting function, in this case `length()` and got the same error you did:

 ![02_year_length](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/2/f/2f47585ffd02510562b8f5af03274e18c9552958.png)

Finally, I joined the year with an empty string (no characters, no spaces) to cast it to a string.

 ![03_year_cast](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/1/f/1f168c155aa2789664daf2694e10805799fea4ee.png)

With this done, you can now use any string functions, including `getSubstring()` on the year.

Hope that helps!

---

<div class="post-metadata">

### Author: ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)
#### Post date: [December 21, 2020, 5:57pm UTC](https://community.thunkable.com/t/cant-get-substring-of-current-year/1040701/3 "2020-12-21T17:57:32Z")

</div>

@domhnallohanlon I appreciate the quick response – and the explanation about the current year block returning a date type.

But I don’t understand what the blocks would look like to access the value of the current year using the _length_ block.

---

<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: [December 21, 2020, 7:16pm UTC](https://community.thunkable.com/t/cant-get-substring-of-current-year/1040701/4 "2020-12-21T19:16:05Z")

</div>

I used this and it worked for me.

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

I used other characters and it worked fine but not an empty string.

---

<div class="post-metadata">

### Author: ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)
#### Post date: [December 21, 2020, 8:24pm UTC](https://community.thunkable.com/t/cant-get-substring-of-current-year/1040701/5 "2020-12-21T20:24:44Z")

</div>

Weird. Okay thank you, that works.

---

<div class="post-metadata">

### Author: ![domhnallohanlon](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/domhnallohanlon/32/29554_2.png) [@domhnallohanlon](https://community.thunkable.com/u/domhnallohanlon)
#### Post date: [December 21, 2020, 11:55pm UTC](https://community.thunkable.com/t/cant-get-substring-of-current-year/1040701/6 "2020-12-21T23:55:53Z")

</div>

> [@domhnallohanlon](#):
>
> With this done, you can now use any string functions, including `getSubstring()` on the year

I just used the `length ()` function because I knew as long as it returned 4 it was ok, once cast to a string you can then get the first two letters using your original approach. It was just sharing a bit about my debugging process I guess? 😃

---

<div class="post-metadata">

### Author: ![domhnallohanlon](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/domhnallohanlon/32/29554_2.png) [@domhnallohanlon](https://community.thunkable.com/u/domhnallohanlon)
#### Post date: [December 21, 2020, 11:58pm UTC](https://community.thunkable.com/t/cant-get-substring-of-current-year/1040701/7 "2020-12-21T23:58:02Z")

</div>

> [@muneer](#):
>
> I used this

@muneer what are you storing in your `ThisYear` variable?

> [@muneer](#):
>
> it worked fine but not an empty string.

This seems odd - it worked fine for me. What happened when you used the empty string?

In this case if you wanted the last two characters you’d get “0#” instead of “20”, right?

---

<div class="post-metadata">

### Author: ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)
#### Post date: [December 22, 2020, 12:00am UTC](https://community.thunkable.com/t/cant-get-substring-of-current-year/1040701/8 "2020-12-22T00:00:55Z")

</div>

I get that part but as soon as I replace the “length” block with anything else, it crashes the app again. So there’s something unique about the length block compared to the get substring block or join block by itself which crash as in these blocks I also posted above:

 ![Screen Shot 2020-12-21 at 9.19.00 AM](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/3/b/3bd5d01252d8a74b14b2323b8c296468962d4d5b.png)

---

<div class="post-metadata">

### Author: ![domhnallohanlon](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/domhnallohanlon/32/29554_2.png) [@domhnallohanlon](https://community.thunkable.com/u/domhnallohanlon)
#### Post date: [December 22, 2020, 12:12am UTC](https://community.thunkable.com/t/cant-get-substring-of-current-year/1040701/9 "2020-12-22T00:12:09Z")

</div>

Very strange indeed. Here’s the project I made to replicate your issue:

> **[Thunkable](https://x.thunkable.com/copy/f620a423c7bf2757597dafed38e31088)**

Push and hold Button2 to see “20” returned.

Does that string contain a space?

---

<div class="post-metadata">

### Author: ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)
#### Post date: [December 22, 2020, 12:37am UTC](https://community.thunkable.com/t/cant-get-substring-of-current-year/1040701/10 "2020-12-22T00:37:13Z")

</div>

Yours works. Mine doesn’t. No space, just an empty string “”

**Edit:** oh, now mine is working, too. Hmm. Okay, then!

---

<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: [December 22, 2020, 7:08am UTC](https://community.thunkable.com/t/cant-get-substring-of-current-year/1040701/11 "2020-12-22T07:08:28Z")

</div>

Hello @domhnallohanlon,  
The variable ThisYear is the block [current year].

> [@domhnallohanlon](#):
>
> In this case if you wanted the last two characters you’d get “0#” instead of “20”, right?

In this case I will use in the substring from letter #3 to letter #4 which should bring “20” or if you run it after the new year then it should give “21”

---

<div class="post-metadata">

### Author: ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)
#### Post date: [December 23, 2020, 2:06am UTC](https://community.thunkable.com/t/cant-get-substring-of-current-year/1040701/12 "2020-12-23T02:06:20Z")

</div>

My apologies for posting blocks to get the substring of the first two characters. I meant the last two (#3 and #4). It doesn’t change the issue at all but it makes more sense since, yes, I’ll want the “21” from 2021 next year. But it’s working for me now so I’m all set.

---

<div class="post-metadata">

### Author: ![ioannis](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/ioannis/32/146956_2.png) [@ioannis](https://community.thunkable.com/u/ioannis)
#### Post date: [November 8, 2024, 12:19pm UTC](https://community.thunkable.com/t/cant-get-substring-of-current-year/1040701/13 "2024-11-08T12:19:32Z")

</div>


