Click here to Skip to main content
15,901,505 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
Hii ,

I am storing companies business data as month and date not storing any year.

based on date and month i want to find out companies current business year

for example if companies business year is set as 1 april then his current business year is as respective to current year is

2014/2015

any logic to find out this year data

I have date and month
Posted
Comments
Thanks7872 22-Jan-15 2:29am    
Its totally meaningless. How on earth 1 april suggests someone that year is 2014/2015? Why not 2011?
Sergey Alexandrovich Kryukov 22-Jan-15 2:31am    
Not storing any year? Congratulations! You lost year information. Good luck.
—SA
nagendrathecoder 22-Jan-15 2:34am    
How can you identify this without storing year? It can be anything.
Torakami 22-Jan-15 2:38am    
the logic is ... on today's date we can see that the companies business date is 1 and month is 4 , and todays month is 22-01 and April hasnt passed this year so its for past year i.e 2014 ...
jaket-cp 22-Jan-15 6:54am    
What happens next year on 2016-01-22?
Should the returned year be 2015?

Is this the sort of thing you want?


C#
int testEndDateMonth = 1;
int testEndDateDay = 20;

//assume end date is in this calendar year
DateTime today = DateTime.Now;
DateTime testDate=new DateTime(today.Year,testEndDateMonth,testEndDateDay);
Console.WriteLine(testDate > today ? "Last Year" : "This Year");
 
Share this answer
 
Comments
BillWoodruff 22-Jan-15 7:42am    
+5 Looks good to me.
Torakami 23-Jan-15 0:10am    
Thanks man , this will work for me ..
George Swan 23-Jan-15 0:54am    
You are very welcome.
Here is a SQL equivalent of solution 1.
SQL
declare @testEndDateMonth int, @testEndDateDay int;
set @testEndDateMonth = 1;
set @testEndDateDay = 20;

declare @testDate datetime;
set @testDate = convert(varchar(4), datepart(year, getdate()))
						+replace(str(@testEndDateMonth, 2), space(1), '0')
						+replace(str(@testEndDateDay, 2), space(1), '0')
;
select 	
case when @testDate > getdate() then
	'Last Year'
else
	'This Year'
end WhatYear;
 
Share this answer
 

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