Week number

yves COPPE yvescoppe at skynet.be
Mon Apr 15 06:56:01 EDT 2002


>Weeks are always seven days or 604800 seconds.
>
>You can find the seconds for the first day of any year by doing this
>(theYear is the year you are working in)
>   put theYear&",1,1,0,0,0" into theYear
>   convert theYear to seconds
>
>Next you can find the seconds for the date you have in question (theDay is
>the day in question and theMonth is the month in question)
>   put theYear&","&themonth&","&theDay&","0,0,0" into theDate
>   convert theDate to seconds
>
>Now figure out how many weeks between the first day of the year and the date
>you have in question
>   put ((theDate-theMonth) div 604800) +1 into theWeeks
>
>If the first day of the year is a Mon then the above calculates a week from
>Mon to Sun as a week. If the first day of the year is a Thus the above
>calculates a week from Thus to Wed and so on.
>
>If you want the week to begin on a particular day you need to know the day
>of the week the year begins. The following handler is 'hard wired' for a Mon
>to Sun week and uses the above information to calculate the week number:
>
>on mouseUp
>   ask "What date?"
>   convert it to dateItems
>   put it into yearStart
>   put "1,1" into item 2 to 3 of yearStart
>   convert yearStart to dateItems
>   put (item 7 yearStart-1)* 86400 into dayDif
>   convert yearStart to seconds
>   convert it to seconds
>   answer "Week"&&(it-yearStart+dayDif)/86400  div 7 +1&&"of the year."
>end mouseUp
>
>If you want to change the day the week starts then a more general solution
>for dayDif is needed.
>
>You don't need to worry about leap year or how many days are in a month. The
>convert function and the length of a week in seconds takes care of this
>naturally.
>
>michael
>


I have a problem with the convert command :
if you use a european format of date and ask "convert", it cannot work

for example :

today
  US : 04/15/2002
Eur : 15/04/2002

when you ask what date and answer : 15/04/2002 : the script cannot run to end.

what to do ??
-- 
Greetings.

Yves COPPE

Email : yvescoppe at skynet.be



More information about the use-livecode mailing list