working with dates

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

fko
Posts: 61
Joined: Tue May 20, 2014 2:13 pm

Re: working with dates

Post by fko » Sun Jun 08, 2014 8:30 pm

Hi Bernd,

This is my code:


global theDataGridArrayNames
global theDataGridArray
global counterP
put 1 into i
put false into isFinished
put the date into dateToday
convert dateToday to system date
put dateToday into dateTodaySeconds
convert dateTodaySeconds to seconds

put 1 into indexP
repeat while i <= counterP and isFinished is not true

put the word 2 of theDataGridArray[theDataGridArrayNames[8]["name"]] into nDays
put theDataGridArray[theDataGridArrayNames[3]["name"]] into tDate
convert tDate from system date to dateItems

add nDays to item 3 of tDate

convert tDate from dateItems to system date
put tDate into tDateSeconds
convert tDateSeconds from system date to seconds

if tDateSeconds <= dateTodaySeconds then
put theDataGridArray[theDataGridArrayNames[1]["name"]] into tdataUsers[indexP]
add 1 to indexP
put empty into tDate
else
end if
if i < counterP then
add 1 to i
else
put true into isFinished
end if
end repeat



I Will try your code and i will tell you...:-)

regards,
fko

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4174
Joined: Sun Jan 07, 2007 9:12 pm

Re: working with dates

Post by bn » Sun Jun 08, 2014 8:46 pm

Hi fko,

I took your code and reduced it.

Code: Select all

on mouseUp
   put the date into dateToday
   convert dateToday to system date
   put dateToday into dateTodaySeconds
   convert dateTodaySeconds from system date to seconds -- this is the offending line "from system date " was missing
   
   
   put 3 into nDays
   put the system date into tDate
   convert tDate from system date to dateItems
   
   add nDays to item 3 of tDate
   
   convert tDate from dateItems to system date
   put tDate into tDateSeconds
   convert tDateSeconds from system date to seconds
   
   if tDateSeconds <= dateTodaySeconds then
      answer "past"
   else
      answer "coming"
   end if
end mouseUp
the offending line is

Code: Select all

convert dateTodaySeconds to seconds
it should be

Code: Select all

 convert dateTodaySeconds from system date to seconds
it is marked in the code as comment. When this change is applied this works form me whether I put

Code: Select all

put 3 into nDays
or

Code: Select all

put -3 into nDays
I think this is the problem you are having.

Kind regards
Bernd

Kind regards
Bernd

fko
Posts: 61
Joined: Tue May 20, 2014 2:13 pm

Re: working with dates

Post by fko » Sun Jun 08, 2014 8:57 pm

Hi Bernd,

Thanks for your help...:-)

Now it is working fine!!!

I tried adding ndays as you said : "add nDays to item 3 of tDate"
and i also tried "subtract nDays from item 3 of tDate"

and it is working well the if sentence...

Thanks for your help once again!!! :-)

regards,
fko

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4174
Joined: Sun Jan 07, 2007 9:12 pm

Re: working with dates

Post by bn » Sun Jun 08, 2014 9:04 pm

Hi fko,

glad it works.

I strongly suggest when trouble shooting: reduce the problem and/or use the debugger to see what is in the variables.
Step through your code. That is how I found out that the conversion to seconds did not happen in your example.
Especially when you work on tricky things like dates/system date/dateItems/seconds.

Kind regards
Bernd

fko
Posts: 61
Joined: Tue May 20, 2014 2:13 pm

Re: working with dates

Post by fko » Sun Jun 08, 2014 9:28 pm

Hi Bernd,

Yes, you are right...It is a good council to reduce to the minimmum to can follow better the code and debug...

I couldn't imagine that the solution was add one 'from' in the convert instruction...

I think i am still not 100% used to the fonctionment of LiveCode...Because in other languages it is not always obliged to say from, as there is the option to define 'Types' to the variables...

anyway, i like LiveCode each day more and more...:-)

Thanks for all!!! :-)

regards,
fko

Post Reply