健康一贴灵,专注医药行业管理信息化

C# 日期格式转换(年月转换成日期)(年加1,月加1,日减1)

 查询员工ID

select partner, bu_sort2,xdele,mc_name1  from but000 where bu_Group='Z005'

 

 string beginDate, endDate;
                //年月格式 :202201
                beginDate =  frmFlowWhere.BeginMonth;
                endDate = frmFlowWhere.EndMonth;
                int month1, month2;
                month1 = Convert.ToInt32(beginDate.Substring(4, 2));
                month2 = Convert.ToInt32(endDate.Substring(4, 2));
                month1++;
                month2++;
                if (month1 ==13)
                {
                    beginDate = Convert.ToInt32(beginDate.Substring(0, 4)) + 1.ToString() + "-01-01 00:00:00";
                }
                else
                {
                    beginDate = beginDate.Substring(0, 4)  + ("-0"+month1.ToString())+"-01 00:00:00";
                    beginDate = beginDate.Replace("-00", "-0");
                }

                   
                if (month2 == 13)
                {
                    endDate = Convert.ToInt32(endDate.Substring(0, 4)) + 1.ToString() + "-01-30 23:59:59";
                    
                }
                else
                {
                    endDate = endDate.Substring(0, 4) + ("-0" + month2.ToString()) + "-01 23:59:59";
                    endDate = endDate.Replace("-00", "-0");
                }
                DateTime dtTest = DateTime.Parse(endDate);
                dtTest = dtTest.AddMonths(1).AddDays(-1);

                endDate = dtTest.ToShortDateString();//最后一天

 

posted @ 2022-07-05 13:41  一贴灵  阅读(1315)  评论(0编辑  收藏  举报
学以致用,效率第一