获取前12个月的时间

            //获取当前时间;  2020-05


            var d_n = DateTime.Now;
            StringBuilder sb = new StringBuilder();
            sb.AppendFormat(" select '{0}' AS M ", d_n.ToString("yyy-MM"));
            for (int i = 1; i < 12; i++)
            {
                sb.AppendFormat(" UNION ALL select '{0}' ", d_n.AddMonths(-i).ToString("yyy-MM"));
            }
            var sql = sb.ToString();

 

posted @ 2021-06-03 09:26  enych  阅读(177)  评论(0编辑  收藏  举报