adding a decimal amount to a date

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

herbwords
Posts: 70
Joined: Sat Dec 01, 2007 2:59 am

Re: adding a decimal amount to a date

Post by herbwords » Tue Mar 05, 2013 3:26 am

OK, I think I see what the problem is. I wanted to give them the option to have any time period on the fly so I added an "other" option:

on tUnitFG
put the date into myDate
convert myDate to dateItems
ask "How long before this item expires? (Ex: 1.25 (15 months), 1.5 (18 months), 1.75 (21 months), 2 (2 years), etc.)"
put it into sDateFG
put (sDateFG * 12) into item 2 of myDate
convert myDate to short date
put myDate into fld "exDate"
end tUnitFG

This is what doesn't work with .3 and such.

Any ideas?

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: adding a decimal amount to a date

Post by Simon » Tue Mar 05, 2013 3:37 am

OK,
use trunc or round eg:

Code: Select all

put round(sDateFG * 12) into item 2 of myDate
--or
put trunc(sDateFG * 12) into item 2 of myDate
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

herbwords
Posts: 70
Joined: Sat Dec 01, 2007 2:59 am

Re: adding a decimal amount to a date

Post by herbwords » Tue Mar 05, 2013 7:17 pm

Hi,

I just wanted to resolve this thread for the sake of anyone that has this same situation. I switched everything to months. I can have someone choose the number of months and store it in one of the fields and then add it to item 2 of dateItems. I did this on the arbitrary and on the fly versions below.

Thanks Simon and John, Great stuff!

on tUnitFG -- on the fly
put the date into myDate
convert myDate to dateItems
ask "How many months before this item expires? (Ex: 13 (1year 1 month), 24 (2 years), etc.)"
put it into sDateFG
add sDateFG to item 2 of myDate
convert myDate to short date
put myDate into fld "exDate"
end tUnitFG


on gramExp --arbitrary (value stored as preferences)
put the date into myDate
convert myDate to dateItems
add fld "setDateD" of cd "inventory1" of stack "inventory" to item 2 of myDate
convert myDate to short date
put myDate into fld "exDate"
end gramExp

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: adding a decimal amount to a date

Post by mwieder » Wed Mar 06, 2013 1:01 am

(Devil's advocate here)...

What happens if the answer to
ask "How many months before this item expires? (Ex: 13 (1year 1 month), 24 (2 years), etc.)"
is 3.1416?

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: adding a decimal amount to a date

Post by Simon » Wed Mar 06, 2013 1:32 am

Mark,
I was biting my tongue on that question!
I put too much time in answering the OP :x

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Post Reply