如何在文本框中显示上个月的上一个日期 [英] How to show previous month last date in Text box
本文介绍了如何在文本框中显示上个月的上一个日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的专家!
我使用一个文本框作为回溯日期。并使用一个dateTimepicker。如果我想从datetimepicker1中选择任何日期,则文本框日期值应该是上个月的最后一个日期,如30s或31st(30-01-2014或31-01-2014)。怎么做。请帮助我。
提前致谢和问候
Sreeni ....
Dear Experts!
I am using one Text Box for back date purpose. And using one dateTimepicker. if I want pick the any date from datetimepicker1, the text box date value should be previous month last date like 30s or 31st (30-01-2014 or 31-01-2014). how to do it. kindly help me.
Advance Thanks & Regards
Sreeni....
推荐答案
DateTime value = new DateTime(DateTime.Now.Year,DateTime.Now.Month,1).AddDays(-1);
DateTime value = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).AddDays(-1);
private void YourDateTimePicker_ValueChanged(object sender, EventArgs e)
{
DateTime val = YourDateTimePicker.Value;
int pYear = val.Year;
int pMonth = val.Month - 1;
if (pMonth == 0)
{
pMonth = 12;
pYear--;
}
DateTime lastDayPrevMonth = new DateTime(pYear, pMonth, DateTime.DaysInMonth(pYear, pMonth));
YourTextBox.Text = lastDayPrevMonth.ToString("dd-MM-yyyy");
}
这篇关于如何在文本框中显示上个月的上一个日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文