[Zope] Retrieving the week number from strftime()

Jacob Lundqvist jaclu@galdrion.com
Mon, 20 Nov 2000 15:41:44 +0100


Ok this is not the quickest of responses ;)

I found an old thread about week numbers, where you suggested dividing the 
dayOfYear by 7

That only works if the year starts on the first day of week

What surprised me is that the normal python method wasn't mentined anywhere 
in the thread

I think simpler is:

ZopeTime().strftime('%U')   # Sunday as firtst day
ZopeTime().strftime('%W')   # Monday as firtst day


Gives you current week as a two diggit number

	/Jacob Lundqvist


torsdag 03 augusti 2000 04:21 skrev du:
> I suspect there is no 'standard' definition of week number.
>
> E.g. if the year begins on a Wednesday, is the following Monday part
> of week 1 or week 2?
>
> Once you decide, you can design a calculation starting with
> "some_date_object.dayOfYear()" which will give you the day number in
> the range 1 to 365 (or 366).
>
> The simplest algorithm would be to say days 1-7 are week 1, 8-14
> are week 2, etc.  In that case
>
>              ((some_date_object.dayOfYear() - 1) / 7) + 1
>
> (or in dtml)
>
>   <dtml-var "((some_date_object.dayOfYear() - 1) / 7) + 1">
>
> will compute a week number (in the range 1 to 53).
>
>
> If your weeks must begin on Sundays, or Mondays, or whatever, you'll
> have to first request the dow() from the first day of the relevant
> year, and do a calculation based on how far into the week the first
> calendar day of the year falls.  If you want help with that,
> describe the algorithm you want to use.
>
> Good luck.
>
> Arjan Scherpenisse <acscherp@wins.uva.nl> writes:
> > Hello,
> >
> > i want to retrieve the number of the week from a DateTime object. Is
> > there any way to do this? I've looked through DateTime.py but i
> > couldnt find anything usefull, is there some algorithm to get this?
>
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists -
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )