Date Calculation

Peter Haworth pete at lcsql.com
Thu Nov 29 16:14:38 EST 2012


Hi Andrew,
Do you by any chance have an sqlite database in your application?  If so, I
can send you a one-line SELECT statement for each date you're looking for
that will do all this for you.
Pete
lcSQL Software <http://www.lcsql.com>



On Thu, Nov 29, 2012 at 12:23 PM, Andrew Kluthe <andrew at ctech.me> wrote:

> That's what I'm looking for! Great.
>
> However, I tried what I think I am supposed to do in the script below
> and my dates are about three days off.
>
> This function is supposed to give me the date for monday of the week
> where the date paramater is.
>
> If the paramater is empty it uses todays date.
>
> function DetermineWeek pDate
>    if pDate is empty then
>       put the date into sDate
>    else
>       put pDate into sDate
>    end if
>    convert sDate to dateItems
>    answer sDate
>    set the itemDelimiter to ","
>    put item -1 of sDate into sDay
>    switch sDay
>       case "2" --Monday
>          put 0 into sDiff
>       case "3" --Tuesday
>          put 1 into sDiff
>       case "4" --Wednesday
>          put 2 into sDiff
>       case "5" --Thursday
>          put 3 into sDiff
>       case "6" --Friday
>          put 4 into sDiff
>       case "7" --Saturday
>          put 5 into sDiff
>       case "1" --Sunday
>          put 6 into sDiff
>    end switch
>    put item 3 of sDate into sDayOfMonth
>    put sDayOfMonth - sDiff into sNewDay
>    put sNewDay into item 3 of sDate
>    answer sDate
>    convert sDate to date
>    return sDate
> end DetermineWeek
>
> For instance leaving the paramater blank should provide me today
> (11/29/12) with a date of 11/26/12 but instead I am returned 11/23/12.
> Maybe I don't properly understand your process for doing this.
>
> On Wed, Nov 28, 2012 at 10:03 AM, Devin Asay <devin_asay at byu.edu> wrote:
> >
> > On Nov 28, 2012, at 8:33 AM, Andrew Kluthe wrote:
> >
> >> Hey Ya'll,
> >>
> >> I thought I had this figured out but I don't and I am not sure where
> >> to go from here.
> >>
> >> I want to retreive the date for the monday and the sunday of the
> current week.
> >>
> >> For instance, if it were today 11/28/2012 then I would want to return
> >> 11/26/2012 and 12/2/2012 . I was trying to leverage Sara R's Date &
> >> Time library, but even with all those lovely functions I still can't
> >> get what I am after. I know there has to be a simpler way of doing
> >> this than the broken mess I was coming up with. How would you tackle
> >> this problem?
> >
> > Andrew,
> >
> > Convert the date to date items, then using the last item (numeric day of
> the week), calculate how many days between today and the preceding Monday
> and the following Sunday.
> > Once you have that, just add (or subtract) the difference to item 3 of
> the date items, then reconvert to the date. The convert command will adjust
> everything properly in the case of transitions between months and years.
> >
> > If you can't figure it out, let me know and I'll dig through some code
> where I had to do this and post it.
> >
> > HTH
> >
> > Devin
> >
> >
> >
> > Devin Asay
> > Office of Digital Humanities
> > Brigham Young University
> >
> >
> > _______________________________________________
> > use-livecode mailing list
> > use-livecode at lists.runrev.com
> > Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> > http://lists.runrev.com/mailman/listinfo/use-livecode
>
>
>
> --
> Regards,
>
> Andrew Kluthe
> andrew at ctech.me
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>



More information about the use-livecode mailing list