Date Routines in C-Sharp

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a way to figure out from a given date the 'week of the year' or
'quarter of the year' that it exists in?

I need to manage report generation that are required to be done
automitically on a Weekly, Monthly or Quarterly basis using the last run date
and a Weekly, Monthly or Quarterly indicator.
 
Checkout the DatePart method...

Here is from the doc for VB:

Dim FirstDate, Msg As String 'Declare variables.
Dim SecondDate As Date
FirstDate = InputBox("Enter a date:")
SecondDate = CDate(FirstDate)
'Msg = "Quarter: " & Microsoft.VisualBasic.DatePart(DateInterval.Quarter,
SecondDate)
Msg = "Quarter: " & DateAndTime.DatePart(DateInterval.Quarter, SecondDate)
MsgBox(Msg)

HTH,
Greg
 
Whoops.

DateAndTime is also part of Microsoft.VisualBasic namespace

But I would just add a reference, and use it. :)

Greg
 
whornak said:
Is there a way to figure out from a given date the 'week of the year' or
'quarter of the year' that it exists in?

I need to manage report generation that are required to be done
automitically on a Weekly, Monthly or Quarterly basis using the last run date
and a Weekly, Monthly or Quarterly indicator.

I'd look at Calendar.GetWeekOfYear, and probably just divide that into
1-13, 14-26, 27-39, 40-42 for the quarter.
 
Greg

You mean something as this, in a shorten version

\\\
DateTime mydate;
mydate = DateTime.Now;
string msg;
msg = "Quarter: " + DateAndTime.DatePart(DateInterval.Quarter,
mydate,FirstDayOfWeek.Monday,FirstWeekOfYear.Jan1);
///

In my opinion a good idea from you.

:-)

Cor
 
Back
Top