Last post Jul 12, 2019 07:54 AM by samwu
Jul 12, 2019 05:01 AM|Gopi.MCA|LINK
Consider Today is 12-Jul-2019
I want to show in textbox1 01-Apr-2019 i mean last 4 month first date as it goes so on..
Jul 12, 2019 07:35 AM|jimmy69|LINK
try something like this :
DateTime GetFirstDateOfMonth(int month)
var date = DateTime.Now;
var firstDayOfMonth = new DateTime(date.Year, date.Month, 1);
Jul 12, 2019 07:54 AM|samwu|LINK
According to your description, this demo is for your reference.
Get year and month based on today's date and set date to 1, Then subtract the number of months according to the requirement.
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
var today = DateTime.Today;
var month = new DateTime(today.Year, today.Month, 1);
var first = month.AddMonths(-3);
TextBox1.Text = first.ToString(("dd-MMM-yyyy"));