Click here to Skip to main content
14,451,574 members
Rate this:
Please Sign up or sign in to vote.
See more:
How can calculate amount such that:
amount = (current date - end date) * 2
How to write code in SQL to achieve the same.
Updated 2-Jan-15 1:05am
Snesh Prajapati 2-Jan-15 6:06am
Hi krisna...I have updated the question...please check if you need the same only...or make it more clear. Thanks.
krishna97 2-Jan-15 6:10am
SELECT DATEDIFF(day, GETDATE(), ReturnDate)*(select FineLimt from tbl_LibryMemberCategory)

from tbl_LibraryBookIssue

this query used
krishna97 2-Jan-15 6:11am
find out day and multiply by this table select FineLimt from tbl_LibryMemberCategory
Snesh Prajapati 2-Jan-15 6:13am
Is that all working fine now ? or what is error now ?
krishna97 2-Jan-15 6:16am
out put can not given for this query
Snesh Prajapati 2-Jan-15 6:21am
Select (DATEDIFF(day, GETDATE(), ReturnDate) * (select top (1) FineLimit from tbl_LibryMemberCategory))
Snesh Prajapati 2-Jan-15 6:22am
It seems "FineLimt" spelling is wrong....first try small select queries then combine them...Check for if any CASTING needed. Thanks.
Rate this:
Please Sign up or sign in to vote.

Solution 1

SELECT DATEDIFF(d, GETDATE(), endDate) * 2 AS [Days times 2] FROM MyTable
Rate this:
Please Sign up or sign in to vote.

Solution 2

Following code will do that:
DATEDIFF(day,endDate,currentDate) * 2

If needed you can write an "if" confition to check whether output of above code is positive integer or not.
For more:[^]


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100