need to calculate the total days in a month in asp.net
if i have salary is rs 2000 june month having 30 days . so 2000/30 67 rs per day
next month is july salary is same but days is increased as 31. so 2000/31 rs 65 per day
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Khan Abrar AhmedPosted Jun 30, 2014, 2:26 AM
int days = System.DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month);
double salary= 2000;
double salaryperday = salary / days;
VulpesPosted Jun 30, 2014, 5:25 AM
However, if you only want to use this to calculate daily salary, you could wrap it in a method as follows:
and then call it with code such as this:
sudipta sanyalPosted Jun 30, 2014, 2:36 AM
DECLARE @pDate datetime, @no_days INT
SET @pDate = CONVERT(DATETIME,'01/06/2014')-1
SELECT @no_days = CASE WHEN MONTH(@pDate) IN (1, 3, 5, 7, 8, 10, 12) THEN 31
WHEN MONTH(@pDate) IN (4, 6, 9, 11) THEN 30
ELSE CASE WHEN (YEAR(@pDate) % 4 = 0 AND YEAR(@pDate) % 100 != 0) OR (YEAR(@pDate) % 400 = 0)
THEN 29
ELSE 28
END
END
SELECT @no_days as [no_days]
SELECT CAST (('2000'/CAST ( @no_days AS DECIMAL(18,2)))AS DECIMAL(18,2))
selvi subramanianPosted Jun 30, 2014, 12:49 AM
Khan Abrar AhmedPosted Jun 29, 2014, 2:10 AM
Use System.DateTime.DaysInMonth, from code sample:
const int July = 7;
const int Feb = 2;
// daysInJuly gets 31.
int daysInJuly = System.DateTime.DaysInMonth(2001, July);
// daysInFeb gets 28 because the year 1998 was not a leap year.
int daysInFeb = System.DateTime.DaysInMonth(1998, Feb);