Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
2.75/5 (4 votes)
See more:
Dear Sir/Madam,
I have a date textbox in my project. My requirement is Default date for end year March 31. I need to change this year dynamically year by year.

For Example

1.If My date of joining is 14-02-2012,it will show in the textbox 31-03-2011,
If My date of joining is 01-04-2012, it will show in the textbox 31-03-2012,


Note:

1.This will happen on page load
Posted
Comments
Shahin Khorshidnia 23-Mar-12 5:05am    
Why 14-02-2012 returnes 2011 but
01-04-2012 returnes 2012?
What is the basis of your plan?

It is very simple. You can initiate date with DateTime constructor by providing year, month and day values separately as shown in following example.

C#
DateTime dateTime=new DateTime((DOJ.Month>3?DOJ.Year:DOJ.Year-1), 3, 31);    



Hope this help!
 
Share this answer
 
Comments
stanly jeba singh 23-Mar-12 2:50am    
I agree with u. My requirement is if the current date is 22-03-2012, it show in the text box 31-03-2011
[no name] 23-Mar-12 3:48am    
Upto what date you required previous year (financial year end date) date and then after you required nex year (financial year end date) date?
Hi,

Following code may help you:-

C#
int icurrMonth = DateTime.Now.Month;
string sYear="";

  if (icurrMonth < 4)//If joining month is April or less then Previous year
  {
    sYear = (DateTime.Now.Year - 1).ToString();
  }
  else //After April Current Year
  {
   sYear = DateTime.Now.Year.ToString();

  }

txtBox.Text = "31-03-" + sYear;


Note : 1. Replace "txtBox" with your "TextBox ID"
2. Replace "DateTime.Now" with "Date of Joining"
 
Share this answer
 
v2

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