Page 2 of 2

Re: adding a decimal amount to a date

Posted: Tue Mar 05, 2013 3:26 am
by herbwords
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?

Re: adding a decimal amount to a date

Posted: Tue Mar 05, 2013 3:37 am
by Simon
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

Re: adding a decimal amount to a date

Posted: Tue Mar 05, 2013 7:17 pm
by herbwords
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

Re: adding a decimal amount to a date

Posted: Wed Mar 06, 2013 1:01 am
by mwieder
(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?

Re: adding a decimal amount to a date

Posted: Wed Mar 06, 2013 1:32 am
by Simon
Mark,
I was biting my tongue on that question!
I put too much time in answering the OP :x

Simon