Obtains the month between two time periods.

Source: Internet
Author: User

/// <Summary>
/// Obtain the month between two time periods
/// </Summary>
/// <Param name = "startTime"> Start month </param>
/// <Param name = "endTime"> end month </param>
/// <Returns> month string </returns>
Public static string DateFiledMonths (string startTime, string endTime)
{
Try
{
Int index = 0;
String filed = string. Empty;
DateTime c1 = Convert. ToDateTime (Convert. ToDateTime (startTime). ToString ("yyyy-MM "));
DateTime c2 = Convert. ToDateTime (Convert. ToDateTime (endTime). ToString ("yyyy-MM "));
If (c1> c2)
{
DateTime tmp = c1;
C1 = c2;
C2 = tmp;
}
While (c2> = c1)
{
Index ++;
If (index> 12) // determine whether the value is greater than 12 months. if the value is greater than 12 months, the system jumps out of www.2cto.com.
Break;
Filed + = c1.ToString ("yyyy-MM") + "| ";
C1 = c1.AddMonths (1 );
}
Return filed. TrimEnd ('| ');
}
Catch {return null ;}
}
 

From Zhu jintuo's column
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.