Date Calculation

Devin Asay devin_asay at byu.edu
Wed Nov 28 11:03:32 EST 2012


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





More information about the use-livecode mailing list