sqlserver数据库datatime类型用c#访问
1.判断是否为NULL
dt.Rows[i]["TheDate"] is System.dbnull
2.截取日期:先转换为DateTime,再使用ToString()方法
((DateTime)dt.Rows[i]["TheDate"]).ToString("yyyy-MM-dd")
3.得到本月第一天和最后一天
BeginDate.Text = System.DateTime.Now.ToString("yyyy-MM-01");
EndDate.Text = System.DateTime.Parse(System.DateTime.Today.AddMonths(1).ToString
dt.Rows[i]["TheDate"] is System.dbnull
2.截取日期:先转换为DateTime,再使用ToString()方法
((DateTime)dt.Rows[i]["TheDate"]).ToString("yyyy-MM-dd")
3.得到本月第一天和最后一天
BeginDate.Text = System.DateTime.Now.ToString("yyyy-MM-01");
EndDate.Text = System.DateTime.Parse(System.DateTime.Today.AddMonths(1).ToString
("yyyy-MM-01")).AddDays(-1).ToString("yyyy-MM-dd");
浙公网安备 33010602011771号