Solved

Retrieving current week number

Posted on 2001-08-07
4
466 Views
Last Modified: 2008-02-01
Hi,

I want to be able to retrieve the week number of the current date. I looked all over the MSDN help, MSDN online, and even Borland's help, but no luck. Somehow the developers of Win32 and those of VCL didn't think anyone would ever need a week number or something, cause there seem to be no functions for it. All that the date/time functions will give me is day/month/year/minutes/hours/seconds etc, not weeks. I was wondering if there was a function for it or something, either in Win32 or VCL (not in MFC, I'm not allowed to use MFC here).

Thanks in advance,


Paul
0
Comment
Question by:mgdPaul
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 2

Expert Comment

by:Lockias
ID: 6359936
I see from your question that you know how to get the number of days. Assume this is in nDays. Then:
int nWeeks = (int) (nDays / 7) + (nDays % 7);

~Lockias
0
 
LVL 5

Expert Comment

by:proskig
ID: 6359943
The easiest way is to use tm_yday member of tm structure.
tm_yday/7 shall give you week number (could be that you need to add 1).
0
 
LVL 2

Accepted Solution

by:
Lockias earned 100 total points
ID: 6359965
Oops!

 int nWeeks = (int) (nDays / 7);
 int nDayInWeek (nDays % 7);

 You are in the <nDayInWeek> day of the <nWeeks> week.

~Lockias
0
 

Author Comment

by:mgdPaul
ID: 6360009
Thanks!
I take it that there aren't any 'standard' functions or anything for this? I find working with dates and times a true hell in C/C++ .... there are dozens of functions and structures to choose from, and the help leaves it up to you to figure out why you should choose one above the other.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question