# \[Solved\] How to change selected date using date picker by particular number of days

**URL:** <https://community.thunkable.com/t/solved-how-to-change-selected-date-using-date-picker-by-particular-number-of-days/563158>\
**Category:** Questions about Thunkable X\
**Tags:** solved, beginner\
**Created:** [April 10, 2020, 9:22pm UTC](https://community.thunkable.com/t/solved-how-to-change-selected-date-using-date-picker-by-particular-number-of-days/563158 "2020-04-10T21:22:22Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![anannyabaheti07](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@anannyabaheti07](https://community.thunkable.com/u/anannyabaheti07)\
**Post date:** [April 10, 2020, 9:22pm UTC](https://community.thunkable.com/t/solved-how-to-change-selected-date-using-date-picker-by-particular-number-of-days/563158/1 "2020-04-10T21:22:22Z")

</div>

How to change the selected date using date picker by a particular number of days. From the user entered last menstrual date, I wish to calculate the delivery date hence need to add 280 days. Pls help me.

---

<div class="post-metadata">

**Author:** ![actech](https://avatars.discourse-cdn.com/v4/letter/a/3d9bf3/32.png) [@actech](https://community.thunkable.com/u/actech)\
**Post date:** [April 11, 2020, 8:25am UTC](https://community.thunkable.com/t/solved-how-to-change-selected-date-using-date-picker-by-particular-number-of-days/563158/2 "2020-04-11T08:25:13Z")

</div>

Check [https://x.thunkable.com/projects/5ad84528ac733600012ede03/project/properties/designer/](https://x.thunkable.com/projects/5ad84528ac733600012ede03/project/properties/designer/)

---

<div class="post-metadata">

**Author:** ![jared](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jared/32/138473_2.png) [@jared](https://community.thunkable.com/u/jared)\
**Post date:** [April 11, 2020, 12:30pm UTC](https://community.thunkable.com/t/solved-how-to-change-selected-date-using-date-picker-by-particular-number-of-days/563158/3 "2020-04-11T12:30:08Z")

</div>

@actech, this is an awesome use of the new web view component. There’s so much that can be done with Javascript!

---

<div class="post-metadata">

**Author:** ![anannyabaheti07](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@anannyabaheti07](https://community.thunkable.com/u/anannyabaheti07)\
**Post date:** [April 11, 2020, 5:50pm UTC](https://community.thunkable.com/t/solved-how-to-change-selected-date-using-date-picker-by-particular-number-of-days/563158/4 "2020-04-11T17:50:13Z")

</div>

Thanks @actech for your help, this works for the current date. But how to use it for a date selected using date picker. Its not working for same.

---

<div class="post-metadata">

**Author:** ![jared](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jared/32/138473_2.png) [@jared](https://community.thunkable.com/u/jared)\
**Post date:** [April 11, 2020, 7:51pm UTC](https://community.thunkable.com/t/solved-how-to-change-selected-date-using-date-picker-by-particular-number-of-days/563158/5 "2020-04-11T19:51:19Z")

</div>

You’d have to put  
In your own values

---

<div class="post-metadata">

**Author:** ![manyone](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@manyone](https://community.thunkable.com/u/manyone)\
**Post date:** [April 11, 2020, 11:53pm UTC](https://community.thunkable.com/t/solved-how-to-change-selected-date-using-date-picker-by-particular-number-of-days/563158/6 "2020-04-11T23:53:58Z")

</div>

thanks to @actech for this example.  
i made a small project to do your requirement: add 280 days after picking a date from the date picker.  
[https://x.thunkable.com/copy/792f5a5be488cc36900f18f9b9b567f4](https://x.thunkable.com/copy/792f5a5be488cc36900f18f9b9b567f4)

---

<div class="post-metadata">

**Author:** ![anannyabaheti07](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@anannyabaheti07](https://community.thunkable.com/u/anannyabaheti07)\
**Post date:** [April 12, 2020, 7:08am UTC](https://community.thunkable.com/t/solved-how-to-change-selected-date-using-date-picker-by-particular-number-of-days/563158/7 "2020-04-12T07:08:25Z")

</div>

Thanks @actech, @jared @manyone for great help. It worked!!! Is there some way using web view component one can count the days between two dates (the date picked & the current date). This will help us to calculate the exact age of the fetus.

---

<div class="post-metadata">

**Author:** ![actech](https://avatars.discourse-cdn.com/v4/letter/a/3d9bf3/32.png) [@actech](https://community.thunkable.com/u/actech)\
**Post date:** [April 12, 2020, 7:36am UTC](https://community.thunkable.com/t/solved-how-to-change-selected-date-using-date-picker-by-particular-number-of-days/563158/8 "2020-04-12T07:36:57Z")

</div>

[https://x.thunkable.com/projects/5ad84528ac733600012ede03/project/properties/designer/](https://x.thunkable.com/projects/5ad84528ac733600012ede03/project/properties/designer/)

---

<div class="post-metadata">

**Author:** ![anannyabaheti07](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@anannyabaheti07](https://community.thunkable.com/u/anannyabaheti07)\
**Post date:** [April 12, 2020, 12:23pm UTC](https://community.thunkable.com/t/solved-how-to-change-selected-date-using-date-picker-by-particular-number-of-days/563158/9 "2020-04-12T12:23:33Z")

</div>

@actech Actually I wish to calculate the number of days as the difference between the current date and the calculated date of conception. It comes as a text after calculation hence the above code won’t work. How to go ahead??

---

<div class="post-metadata">

**Author:** ![actech](https://avatars.discourse-cdn.com/v4/letter/a/3d9bf3/32.png) [@actech](https://community.thunkable.com/u/actech)\
**Post date:** [April 12, 2020, 2:08pm UTC](https://community.thunkable.com/t/solved-how-to-change-selected-date-using-date-picker-by-particular-number-of-days/563158/10 "2020-04-12T14:08:01Z")

</div>

If you need a different logic, you need to change the code. To do this in [google.com](http://google.com) you need to set the query “javascript subtract dates” and add the resulting code to the app

Example

```
let day_1 = new Date("2019-08-20"),
 day_2 = new Date("2019-10-07");

function diffDates(day_one, day_two) {
 return (day_one - day_two) / (60 * 60 * 24 * 1000);
};

alert(diffDates(day_2, day_1));
```

---

<div class="post-metadata">

**Author:** ![actech](https://avatars.discourse-cdn.com/v4/letter/a/3d9bf3/32.png) [@actech](https://community.thunkable.com/u/actech)\
**Post date:** [April 12, 2020, 2:16pm UTC](https://community.thunkable.com/t/solved-how-to-change-selected-date-using-date-picker-by-particular-number-of-days/563158/11 "2020-04-12T14:16:03Z")

</div>

There is a convenient library for working with dates - moment.js.

If you need additional functionality that is not available in Thunkable X, then you need to learn at least the basics of the Javascript programming language. But this question goes beyond the forum on Thunkable X.

---

<div class="post-metadata">

**Author:** ![anannyabaheti07](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@anannyabaheti07](https://community.thunkable.com/u/anannyabaheti07)\
**Post date:** [April 12, 2020, 6:04pm UTC](https://community.thunkable.com/t/solved-how-to-change-selected-date-using-date-picker-by-particular-number-of-days/563158/12 "2020-04-12T18:04:09Z")

</div>

@actech Thanks a ton!!

---

<div class="post-metadata">

**Author:** ![actech](https://avatars.discourse-cdn.com/v4/letter/a/3d9bf3/32.png) [@actech](https://community.thunkable.com/u/actech)\
**Post date:** [April 14, 2020, 8:00am UTC](https://community.thunkable.com/t/solved-how-to-change-selected-date-using-date-picker-by-particular-number-of-days/563158/16 "2020-04-14T08:00:44Z")

</div>

Okay, I’ll delete mine, too. Thank you for your help in creating a clear example.

---

<div class="post-metadata">

**Author:** ![artificialdama4u](https://avatars.discourse-cdn.com/v4/letter/a/e68b1a/32.png) [@artificialdama4u](https://community.thunkable.com/u/artificialdama4u)\
**Post date:** [May 9, 2020, 5:48pm UTC](https://community.thunkable.com/t/solved-how-to-change-selected-date-using-date-picker-by-particular-number-of-days/563158/17 "2020-05-09T17:48:35Z")

</div>

@actech do you need Internet connection to execute that web-viewer javascript function?

---

<div class="post-metadata">

**Author:** ![jared](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jared/32/138473_2.png) [@jared](https://community.thunkable.com/u/jared)\
**Post date:** [May 10, 2020, 1:43pm UTC](https://community.thunkable.com/t/solved-how-to-change-selected-date-using-date-picker-by-particular-number-of-days/563158/18 "2020-05-10T13:43:12Z")

</div>

you shouldnt need to if you are able to load the javascript library to your app assets folder. then in your page script reference you would locate the file on the phone instead of from a CDN

i am playing with this over the next week.  
@artificialdama4u

---

<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, 11:29am UTC](https://community.thunkable.com/t/solved-how-to-change-selected-date-using-date-picker-by-particular-number-of-days/563158/19 "2024-11-08T11:29:18Z")

</div>


