Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with C# code

Status
Not open for further replies.

rf222

Programmer
Jan 29, 2004
94
US
I have a method called CallGetList(dateTimeFrom, dateTimeTo);

The problem is that it does not accept range with more than 30 days. What I would like to do is to call CallGetList method with range of 30 days several times to cover the whole dateTimeFrom-dateTimeTo range.

Also the range maybe within 30 days, than is OK to call it without splitting.

Please help.
 
What is the code for your method, it has to be something in there.
 
It does not matter of the actual implementation, it is API. I just want to spilt a range DateTimeFrom to DataTimeTo to 30 days intervals and call the method several times, yet minimum one time...
 
You didn't specify that it was by design, you made it sound as if that was the error.
 
Yes, it is by design to accept 30 days period. Sorry.

I would like help (I am kind of new to C#) how to write code to split the range into 30 day intervals and call the sub. Any C# gurus around?
 
Did you mean something like this:

Code:
    public void CallGetList(DateTime from, DateTime to)
    {
        if (from > to)
            throw new ArgumentException("'to' date must be later than 'from'");

        DateTime startTime = from;
        DateTime endTime;

        while (((TimeSpan)(to - startTime)).Days > 30)
        {
            endTime = startTime.AddDays(30);

            //process startTime and endTime

            startTime = endTime;
        }

        endTime = to;

        //process startTime and endTime one last time.
    }
 
Thanks a lot, I will give it a try.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top