"week-year" conversion to date

O

oyvgi

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.
 
R

Rune Strand

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
 
E

Eddie Corns

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.
<DateTime object for '1992-12-23 00:00:00.00' at 81d5448>

Eddie
 
J

Jorgen Grahn

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top