"week-year" conversion to date

Discussion in 'Python' started by oyvgi@hotmail.com, Sep 14, 2005.

  1. Guest

    I was wondering if it there is an "easy" way to get the dd-mm-yyyy from
    ww-yyyy.

    I would like to get, for example the first day (date-month-year) in the
    week i specify. Found plenty of ways to go th other way, but none that
    give me the reverse.

    Idealy I would like both the beginning date/time and the end date/time
    of the specified week, but if i can just get a hold one of the or some
    other defined time in this week i could probably work out the rest.

    This is in Python :)

    dd = day in month
    mm = month
    yyyy = year
    ww = week #

    Thanks for any and all help.
    , Sep 14, 2005
    #1
    1. Advertising

  2. Rune Strand Guest

    year = '2005'
    week = 50
    weekday = 1 # Monday is 1

    time_expr = '%s, %s, %s' % (year, week, weekday)
    time_struct = time.strptime(time_expr, "%Y, %W, %w")
    print time.strftime("%Y%m%d", time_struct)

    But the datetime module may have an easier way
    Rune Strand, Sep 14, 2005
    #2
    1. Advertising

  3. Eddie Corns Guest

    writes:

    >I was wondering if it there is an "easy" way to get the dd-mm-yyyy from
    >ww-yyyy.


    >I would like to get, for example the first day (date-month-year) in the
    >week i specify. Found plenty of ways to go th other way, but none that
    >give me the reverse.


    >Idealy I would like both the beginning date/time and the end date/time
    >of the specified week, but if i can just get a hold one of the or some
    >other defined time in this week i could probably work out the rest.


    >This is in Python :)


    >dd = day in month
    >mm = month
    >yyyy = year
    >ww = week #


    >Thanks for any and all help.


    >>> import mx.DateTime
    >>> d=mx.DateTime.DateTime(1992)+mx.DateTime.RelativeDateTime(weeks=15)
    >>> d

    <DateTime object for '1992-04-15 00:00:00.00' at 81d5410>
    >>> d=mx.DateTime.DateTime(1992)+mx.DateTime.RelativeDateTime(weeks=51)
    >>> d

    <DateTime object for '1992-12-23 00:00:00.00' at 81d5448>

    Eddie
    Eddie Corns, Sep 14, 2005
    #3
  4. Guest

    Thanks!

    Both solutions worked perfectly.
    , Sep 15, 2005
    #4
  5. Jorgen Grahn Guest

    On 14 Sep 2005 06:26:01 -0700, <> wrote:
    > I was wondering if it there is an "easy" way to get the dd-mm-yyyy from
    > ww-yyyy.


    Note that there are different standards[0] for assigning numbers to weeks in a
    year. Whatever software or algorithm you use, make sure it documents which
    one it implements.

    /Jorgen

    [0] If I recall correctly, one is an ISO standard and is the used in Sweden
    and in BSD ncal(1), but there are others that could be in common use in
    parts of the world.

    --
    // Jorgen Grahn <jgrahn@ Ph'nglui mglw'nafh Cthulhu
    \X/ algonet.se> R'lyeh wgah'nagl fhtagn!
    Jorgen Grahn, Sep 17, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt
    Replies:
    1
    Views:
    572
    Matthew Speed
    Nov 8, 2003
  2. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,196
    Michael Borgwardt
    May 30, 2004
  3. Matt
    Replies:
    2
    Views:
    494
    Pete Becker
    Nov 8, 2003
  4. Matt
    Replies:
    3
    Views:
    695
    Richard Heathfield
    Nov 8, 2003
  5. Sanjeeb
    Replies:
    2
    Views:
    170
Loading...

Share This Page