Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8338877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:43:35+00:00 2026-06-09T04:43:35+00:00

I have a webservice which accepts the date range and due to huge data

  • 0

I have a webservice which accepts the date range and due to huge data import i am passing the date range parameters for 1 month only.

Acceptable start date format : 1-apr-2012

Acceptable end date format : 30-apr-2012

I want programatically send each month’s start and end dates for last 2 years
like 1-Jan-2012 till 31-aug-2012

Below is sample piece of code which i started to test but its giving me span of 30 days when end date plus 1 month is added.

static void Main(string[] args)
    {
        string startDt = "1-apr-2011";
        string endDt = "30-apr-2012";
        DateTime dt = Convert.ToDateTime(startDt);
        DateTime dt2 = Convert.ToDateTime(endDt);
        CultureInfo culture = CultureInfo.GetCultureInfo("en-GB");

        //Console.WriteLine(value.ToString("D", culture)); 

        while (dt < dt2)
        {
            Console.WriteLine(dt.ToString("D", culture));
           // Console.WriteLine(String.Format("{0:dd-MM-yyyy}", dt));
            dt = dt.AddMonths(1);                
        }
        Console.ReadLine();
    }

Corrected Code:

 static void Main(string[] args)
    {
        string startDt = "1-apr-2011";
        string endDt = "30-apr-2012";
        DateTime dt = Convert.ToDateTime(startDt);
        DateTime dt2 = Convert.ToDateTime(endDt);
        CultureInfo culture = CultureInfo.GetCultureInfo("en-GB"); 
        while (dt < dt2)
        {
            DateTime dtend = new DateTime(dt.Year, dt.Month, DateTime.DaysInMonth(dt.Year, dt.Month)); 
            Console.WriteLine(dt.ToString("D", culture));
            Console.WriteLine(dtend.ToString("D", culture));               
            dt = dt.AddMonths(1);                
        }
        Console.ReadLine();
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T04:43:37+00:00Added an answer on June 9, 2026 at 4:43 am

    Every month first date will be 1 but for last date you have to use

    int DateTime.DaysInMonth(int year, int month);
    

    This takes month because month can be 28, 29, 30 or 31 days and takes year for leap year consideration.

    Adding AddMonth(1) to last date of a month does not necessary means it will give last date of next month.

    Picture this scenario

    DateTime dtt = new DateTime(2012, 09, 30);
    
    dtt = dtt.AddMonths(1);
    

    Now 30-Sept is last date of September but when we AddMonth(1) it gives us 30-October. But last date of October is 31st not 30th.

    so if for January first date will be

    DateTime startdateofamonth = new DateTime(2011, 1, 1);
    

    while last date will be

    DateTime lastdateofamonth = new DateTime(2011, 1, DateTime.DaysInMonth(2011,1));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a restful webservice which receives some structured data which is put straight
I have an application in which I have a webservice call that returns data
I have to call a third party webservice that expects and only accepts illegal
Hi Given I have a webservice which accepts file uploads. And I want to
We have implemented webservice which generates xml response. I am facing issue while invoking
I have a .NET webservice which I need to hit asynchronously from the jQuery
I have a webservice programmed in coldfusion which I'm attempting to consume using c#.net.
I have a webservice project (old asmx technology) in which I have a class
I have devoloped a WebService (WS1) in Java which is deployed in a Tomcat
I have a winforms, and it connecting wit webservice. Webservice has method which create

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.