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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Khan Abrar AhmedRank #778 · 3K reputationPosted Jun 29, 2014, 10:26 PM EDT
int days = System.DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month);
double salary= 2000;
double salaryperday = salary / days;
sudipta sanyalRank #1,945 · 753 reputationPosted Jun 29, 2014, 10:36 PM EDT
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))
Khan Abrar AhmedRank #778 · 3K reputationPosted Jun 28, 2014, 10:10 PM EDT
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);
selvi subramanianRank #2,007 · 723 reputationPosted Jun 29, 2014, 8:49 PM EDT
VulpesRank #55 · 29.2K reputationPosted Jun 30, 2014, 1:25 AM EDT
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: