zoukankan      html  css  js  c++  java
  • C# 计算月之间的月份集合

    public static string StructSql(int startYear, int startMonth, int endYear, int endMonth)
            {
                StringBuilder tempSql = new StringBuilder();
                DateTime dtStart = new DateTime(startYear, startMonth, 1);
                DateTime dtEnd = new DateTime(endYear, endMonth, 1);
                TimeSpan ts = dtEnd - dtStart;
                int tempStartYear = startYear;
                int tempStartMonth = startMonth;
                if (ts.TotalDays > 25)
                {

                    for (int i = startMonth; i <= 12; i++)
                    {
                        if (i == startMonth && tempStartYear == startYear)
                            tempSql.AppendFormat("select '{0}' as A,'{1}' as B from dual\n", tempStartYear.ToString(), tempStartMonth.ToString());
                        else
                            tempSql.AppendFormat(" union all select '{0}' as A,'{1}' as B from dual\n", tempStartYear.ToString(), tempStartMonth.ToString());


                     
                        if (tempStartYear >= endYear && tempStartMonth >= endMonth)
                            break;

                        if (i == 12)
                        {
                            tempStartYear++;
                            i = 0;
                            tempStartMonth = 0;

                        }

                        tempStartMonth++;
                     
                    }
                }
                else
                {
                   // Page.RegisterStartupScript("message", "<script type='text/javascript'>alert('查询的截至时间小于一个月不能查询!')</script>");
                    return "";
                    //Response.End();
                }
                return tempSql.ToString();
            }

  • 相关阅读:
    原创 | 我被面试官给虐懵了,竟然是因为我不懂Spring中的@Configuration
    vavr:让你像写Scala一样写Java
    Java黑科技之源:JVMTI完全解读
    JVM 源码解读之 CMS 何时会进行 Full GC
    MySQL 如何优化大分页查询?
    025:为什么需要将Logger对象声明为private static final类型的
    酷家乐一面二面
    趋势科技面试
    生活就是好好经历,无问西东----三月份总结
    30号快手笔试(三道ac两道半)————-历史上最大的网络失误orz
  • 原文地址:https://www.cnblogs.com/bestsaler/p/1835438.html
Copyright © 2011-2022 走看看