Jump to content

Convert [Year WeekNumber] string to [YearMonthDay] string


Recommended Posts

Hi all,

I have to convert a string like 9 34, which means year 2009 and week number 34 to a string like 090818, whiche means year 2009, month 08 and day 18 (first day of this week).

I try to scan my first string to a timestamp with %<%y %W>T format then format this new string with %<%y%m%d>T format but it does'nt work.

The problem is to convert the week number.

Anybody has an idea ?

Thanks all,

Callahan

Link to comment

QUOTE (Callahan @ Mar 26 2009, 10:15 AM)

Hi all,

I have to convert a string like 9 34, which means year 2009 and week number 34 to a string like 090818, whiche means year 2009, month 08 and day 18 (first day of this week).

I try to scan my first string to a timestamp with %<%y %W>T format then format this new string with %<%y%m%d>T format but it does'nt work.

The problem is to convert the week number.

Anybody has an idea ?

Thanks all,

Callahan

Hi,

I couldn't find anything related to the week number in the documentation for scanning from a string.

The "format date/time string" does support the %W, but the "scan from string" seems not to support it. :(

I assume you will have to read the week number as a integer and do the calculation yourself...

Link to comment

QUOTE (Antoine Châlons @ Mar 26 2009, 02:05 AM)

I assume you will have to read the week number as a integer and do the calculation yourself...

Rather than computing the week number, you could just start with January 1 of that year, and in a while loop, keep adding 24 hours and checking the week number until it matches.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.