Click here to Skip to main content
15,742,882 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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

DateTime value = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).AddDays(-1);
Share this answer
sreenivashan 19-Nov-14 7:23am    
Dear murkalkiran... this code working well and good. But I need if I am select from datePicker the value shold change. for example: the datepicker date is: 19-11-2014. if select any date from current month like 11th month, the textbox date value must be 31-10-2014. Moreover if i am select any date from 10th month, the text box value must be 30-09-2014 like only.
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;

    DateTime lastDayPrevMonth = new DateTime(pYear, pMonth, DateTime.DaysInMonth(pYear, pMonth));

    YourTextBox.Text = lastDayPrevMonth.ToString("dd-MM-yyyy");
Share this answer
sreenivashan 20-Nov-14 2:54am    
thanks and lot... working good..

Once Thank you so much..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900