Date Calculation

Andrew Kluthe andrew at ctech.me
Thu Nov 29 16:13:02 EST 2012


duh. I got focused on getting the concept of the process and wasn't
even looking for script errors like that. jeez.

Thanks a million, J and Devin.

Andrew

On Thu, Nov 29, 2012 at 2:51 PM, J. Landman Gay
<jacque at hyperactivesw.com> wrote:
> On 11/29/12 2:23 PM, Andrew Kluthe 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.
>
>
> You forgot the "break" statements in the switch. Everything will fall
> through to a difference of 6.
>
> --
> Jacqueline Landman Gay         |     jacque at hyperactivesw.com
> HyperActive Software           |     http://www.hyperactivesw.com
>
>
> _______________________________________________
> 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




More information about the use-livecode mailing list