Skip to first unread message

Ariel Flaks

unread,
Mar 6, 2017, 1:12:11 PM3/6/17
to mitappinv...@googlegroups.com
Hi friends, I have a problem, and I can´t solve it
I have two dates, one from the datepicker and one from the current date, what I want to do is to have the diferences in days from one date to other.
I made the blocks and it work, but for some dates i goes wrong, for eg. today is 6/3/2017 and pick the date 11/03/2017 and it work.. but if I pick 15/3/2017 I have worng answer...356 days!!!.
What do you think that I am doing wrong?
thanks


Taifun

unread,
Mar 6, 2017, 2:57:18 PM3/6/17
to MIT App Inventor Forum
see the documentation and define fecha_fut accordingly
http://ai2.appinventor.mit.edu/reference/components/sensors.html#Clock

InstantInTime MakeInstant(text from)
Returns an instant specified by MM/DD/YYYY hh:mm:ss or MM/DD/YYYY or hh:mm. An example text input is "06/22/2015 12:18"

also you could simplify a little bit, see screenshot...
and: use Do it to debug your blocks, see tip 4 here

Top 5 Tips: How to learn App Inventor


Taifun

Trying to push the limits of App Inventor! Snippets, Tutorials and Extensions from Pura Vida Apps by Taifun. 

Ariel Flaks

unread,
Mar 6, 2017, 3:17:44 PM3/6/17
to MIT App Inventor Forum
Thanks Taifun for your help, I don´t undestand where is the problem.... I define the variable as dd/MM/YYYY


Also, I simplify as you recommend : 



But still not workin ..
Thanks again
Ariel

Taifun

unread,
Mar 6, 2017, 3:42:08 PM3/6/17
to MIT App Inventor Forum
if you take a look at the documentation, you will realize, that the MakeInstant method needs the format MM/DD/YYYY  and NOT DD/MM/YYYY
Taifun

Abraham Getzler

unread,
Mar 6, 2017, 4:52:20 PM3/6/17
to MIT App Inventor Forum
15/3/2017 is the third of Marchtember,  the 15th month of 2017.
ABG

Ariel Flaks

unread,
Mar 6, 2017, 4:57:46 PM3/6/17
to MIT App Inventor Forum
WOW!!! TAIFUN you are the best!!! many thanks.....
Regards

Rudolph Karstadt

unread,
Mar 6, 2017, 6:17:55 PM3/6/17
to MIT App Inventor Forum
hi,

Even if it is working now,  you will not get the right number of days for every dates. eg. 09/15/2016 - 01/01/2004 = 4641   - you'll get 4640.


rudolph

Taifun

unread,
Mar 6, 2017, 7:27:19 PM3/6/17
to mitappinv...@googlegroups.com
days.aia

Hossein Amerkashi

unread,
Mar 6, 2017, 8:35:17 PM3/6/17
to MIT App Inventor Forum
Alternatively, you could use DateUtils extension that uses much less blocks, auto-calculates leap years and, to my opinion, simpler to use.

foo.png

Rudolph Karstadt

unread,
Mar 6, 2017, 9:56:01 PM3/6/17
to mitappinv...@googlegroups.com
Hi Taifun,

I loaded your days.aia file and I get 4640. maybe this (android) bug is only in the european (german) date format.

I found, that I get correct results by adding 12h.



here is a screenshot from a test app  which shows the wrong dates start at 01/01/2000   614 of 1000




------------------------------------------------
@Hossein

because this bug is an probably an Android thing so I get the same result with the date extension.


i think that is because the start time 0ms is 01/01/1970 1.00 am  and not 0.00



days_test.aia

Ariel Flaks

unread,
Mar 7, 2017, 6:24:05 AM3/7/17
to MIT App Inventor Forum
Thanks a lot for the help!!. You are awesome!

Taifun

unread,
Mar 7, 2017, 6:18:29 PM3/7/17
to MIT App Inventor Forum
@Rudolf: if you calculate the duration in hours, whats the difference then? 1 hour? probably it's a daylight saving time issue then?
which Android version are you using?
Taifun

Abraham Getzler

unread,
Mar 7, 2017, 6:29:24 PM3/7/17
to MIT App Inventor Forum
Maybe it's an International Date Line problem, like 
in Around the World in 80 Days?

What's the time zone and date setting in the device or emulator?


ABG

Rudolph Karstadt

unread,
Mar 7, 2017, 7:12:31 PM3/7/17
to mitappinv...@googlegroups.com
Hi,
yes it is 1 hour diff. 4640d 23h


using
Samsung S2 -  Android 4.12
Tablet - Android 4.03
Tablet - Android 4.42

time zone:

just testing dates between DST 0 +1h     (give me 20 min)

Taifun

unread,
Mar 7, 2017, 7:21:31 PM3/7/17
to mitappinv...@googlegroups.com
ok
what happens, if you try to get the duration between 01/01/2004 and 11/01/2016 (i.e. a date outside of the daylight saving time)?
Taifun

Rudolph Karstadt

unread,
Mar 7, 2017, 7:48:54 PM3/7/17
to mitappinv...@googlegroups.com
hi

you are right

it is the DST  

DST starts in Germany at march , 26   2.00am -> 3.00am  

(Test start  03/20/2017  tested with the DateUtils extension)

and then starts the 1h difference.

and ends October, 29   3.00am -> 2.00am

and i got the day back


So everything works, if you add 1h (i did 12h) to the date difference (in ms) . That is how I solved the problem.  And now I learned why ;-)

as a  matter of fact Android is right, because the number of hours (and ms) is correct and 23h are not a day and Android uses the ms to calculate the days 

greetings rudolph

Reply all
Reply to author
Forward
0 new messages