Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > "week-year" conversion to date

Reply
Thread Tools

"week-year" conversion to date

 
 
oyvgi@hotmail.com
Guest
Posts: n/a
 
      09-14-2005
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.

 
Reply With Quote
 
 
 
 
Rune Strand
Guest
Posts: n/a
 
      09-14-2005

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

 
Reply With Quote
 
 
 
 
Eddie Corns
Guest
Posts: n/a
 
      09-14-2005
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.RelativeD ateTime(weeks=15)
>>> d

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

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

Eddie
 
Reply With Quote
 
oyvgi@hotmail.com
Guest
Posts: n/a
 
      09-15-2005
Thanks!

Both solutions worked perfectly.

 
Reply With Quote
 
Jorgen Grahn
Guest
Posts: n/a
 
      09-17-2005
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!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Date, date date date.... Peter Grison Java 10 05-30-2004 01:20 PM
Calling date conversion function before binding the date to a daragrid Sanjeeb ASP .Net Web Controls 2 01-26-2004 06:36 AM
Given a date, how to find the beginning date and ending date of that week Matt ASP .Net 1 11-08-2003 09:14 PM
Given a date, how to find the beginning date and ending date of that week Matt C Programming 3 11-08-2003 09:07 PM
Given a date, how to find the beginning date and ending date of that week Matt C++ 2 11-08-2003 08:30 PM



Advertisments