Click here to Skip to main content
15,893,381 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
i am devloping library management system in asp.net C#. i want to calculate fine by comparing isuue date and return date. Here

Fine is calculated as:

Find the no of days between issue date and return date.

If no of days are greater than 10 then calculate fine using the formula given below

Fine=No. of Days * 10 Rs. (i.e 10 Rs fine per day)

Otherwise there will be no fine.

So i am inserting the record of isuue date in issue table (data type- Date in sql server)

so how i calculate by comparing the return date. please provide sagment of code for it.


this code can given error

SQL
DECLARE @IssueDate date, @Days int
SET @IssueDate = (select IssueDate from tbl_LibraryBookIssue)
SET @Days = DATEDIFF(DAY,(select ReturnDate from tbl_LibraryBookIssue), GETDATE())
SELECT (CASE WHEN @Days > 11 THEN @Days * 10 ELSE 0 END) Fine
Posted
Updated 2-Jan-15 23:17pm
v4
Comments
Wendelius 3-Jan-15 5:12am    
The question isn't very clear. Please add more explanations what you're trying to achieve.
krishna97 3-Jan-15 5:16am    
how can calculate library Book return fine

1 solution

No, that won't work.
Try the simpler version:
SQL
SELECT DATEDIFF(d, IssueDate, ReturnDate) * 10 as Fine from tbl_LibraryBookIssue
WHERE DATEDIFF(d, IssueDate, ReturnDate) > 11




not given out put

SQL
declare @IssueDate datetime,@ReturnDate datetime,@Curr datetime
 
set @IssueDate='2014-12-25 00:00:00.000'
Set @ReturnDate='2015-01-01 00:00:00.000'
Set @Curr=GETDATE()
 
--2 day Extra can fine given
SELECT DATEDIFF(d, @ReturnDate, @Curr) * 10 as Fine from tbl_LibraryBookIssue
WHERE DATEDIFF(d, @IssueDate,@ReturnDate) > 7
--select * from tbl_LibryMemberCategory


Um...
25, 26, 27, 28, 29, 30, 31, 1
   1   2   3   4   5   6   7

So the date diff is equal to 7, not greater than...
 
Share this answer
 
v2
Comments
krishna97 3-Jan-15 6:06am    
not given out put

declare @IssueDate datetime,@ReturnDate datetime,@Curr datetime

set @IssueDate='2014-12-25 00:00:00.000'
Set @ReturnDate='2015-01-01 00:00:00.000'
Set @Curr=GETDATE()

--2 day Extra can fine given
SELECT DATEDIFF(d, @ReturnDate, @Curr) * 10 as Fine from tbl_LibraryBookIssue
WHERE DATEDIFF(d, @IssueDate,@ReturnDate) > 7
--select * from tbl_LibryMemberCategory
OriginalGriff 3-Jan-15 6:21am    
Answer updated

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