Date calculations
Sarah
sarahr at genesearch.com.au
Tue Jul 15 13:44:01 EDT 2003
Hi Ubaldo,
The easiest way is to convert your dates to "the seconds" i.e. the
number of seconds since 1/1/1970. This way they are a single number
that can be used in all your calculations. The only tricky bit is to
make sure that your dates are in the format that is expected: m/d/y or
d/m/y
Try this script but check that it is giving sensible answers before
telling people when their baby is due :-)
on mouseUp
ask "Enter the LMP date in m/d/y format:" -- this is Rev's standard
format
put it into LMP
if LMP is empty then exit mouseUp -- user clicked Cancel or didn't
enter anything
if LMP is not a date then exit mouseUp -- best to give an error
message here
convert LMP from short date to seconds
put LMP + (60 * 60 * 24 * 280) into EDD -- add 280 days in seconds
convert EDD to short date
answer "EDD (m/d/y): " & EDD
end mouseUp
You might also be interested in the Calendar stack that is available on
my web page. It allows you to select a date graphically, rather than by
typing and so eliminates any errors in date format. You can also return
the result in the localised format by saying "convert EDD to short
system date".
Cheers,
Sarah
sarahr at genesearch.com.au
http://www.troz.net/Rev/
On Wednesday, July 16, 2003, at 08:14 am, Dottor Zivago wrote:
> Dear friends,
> Sorry for another basic question to the list but:
> I would like to have a field as a container for a date, then a button
> that
> performs a calculation on that date and puts the result in another
> field.
> For instance, for a given LMP (last menstrual period) I need to
> calculate an
> EDD (estimated date of delivery) that is simply LMP+280 (and this is
> what I
> do in Excel or FileMaker).
> Pleeeease, assume an IQ<=40; some lines to cut and paste between "on
> mouseup" and "end mouseup" would be very very appreciated.
> Thank you very much
> Ciao
> Ubaldo
More information about the use-livecode
mailing list