Hello All,
I want to calculate the room charges in my application.The condition is,
If any patient registered in between 12.01 AM to 11.59 PM should be applicable for whole day charges as per room segment, i.e. General Ward, Delux, etc,
After 12 AM in night it will be applicable to charge the second day charges as per ward type.
Can anyone suggest me to do that in sql script or in coding?
Thanks for Future Help.

Piyush PansuriyaRank #454 · 5.5K reputationPosted Jan 7, 2015, 3:04 AM EST
If in every cases you have to add one more day than you can use it.
DATEDIFF(DAY, STARTDATE, ENDDATE)+1
Posted Jan 6, 2015, 11:52 PM EST
Your case is not fulfilling my query.
Case 1 : When StartDate is 7/1/2015 and EndDate is also 7/1/2015
In this case DATEDIFF = 0, means it is satisfying your case 1 to add 1.
Case 2 : When StartDate is 7/1/2015and EndDate is 8/1/2015
In case DATEDIFF = 1, where I want it should be 2.Not satisfying else case in your query.
So I should use only DATEDIFF(DAY, STARTDATE, ENDDATE)+1 in every situation.
Please give your valuable suggestion that am I right or wrong?
Piyush PansuriyaRank #454 · 5.5K reputationPosted Jan 6, 2015, 2:34 AM EST
you are doing mistake in AM & PM. 12:01 AM to 11:59 PM means its a 24 Hours.
First you clear your and mine confusion, and you can do simply using if condition.
Posted Jan 6, 2015, 4:01 AM EST
Than After as passed 12 in Night he will be chargeable for next day charges(for 24 hr).
Thanks
Piyush PansuriyaRank #454 · 5.5K reputationPosted Jan 6, 2015, 6:59 PM EST
It means patient comes 11:00 PM and Out 12:01 AM than consider 2 days charges?
if I am not wrong than you can do by date only.
like,
Sql Server : DATEDIFF(DAY, START_DATE, END_DATE)
c# : (EndDate - StartDate).TotalDays
Put if condition as per days charges.
Posted Jan 6, 2015, 9:30 PM EST
Sql Server : DATEDIFF(DAY, START_DATE, END_DATE)
But in this case I have to add +1 in equation(DATEDIFF(DAY, START_DATE, END_DATE))
because if startdate is 7/1/2015 and enddate also is 7/1/2015 than it will give us 0 that is wrong so I have to add 1.
Thanks for giving your precious time for my query.
Piyush PansuriyaRank #454 · 5.5K reputationPosted Jan 6, 2015, 10:56 PM EST
in this situation use CASE in Sql Server
like :
SELECT CASE WHEN DATEDIFF(DAY,START_DATE,END_DATE) = 0 THEN 1 ELSE DATEDIFF(DAY,START_DATE,END_DATE) END
*Like And Accept this answer if helpfull.!!
Vikram AgrawalRank #4,713 · 329 reputationPosted Jan 6, 2015, 11:08 PM EST
you can check this in if condition if startDate and endDate are equal then you can set totalDays as 1 other wise you can get totalDays from your DateDiff() function.
thanks
Hemant SrivastavaRank #581 · 4.2K reputationPosted Jan 7, 2015, 9:19 AM EST
Yes, For your problem
SELECT DATEDIFF(DAY, @STARTDATE, @ENDDATE) + 1 is correct in every case
For example:
DECLARE @STARTDATE DATETIME
SET @STARTDATE = '2015-01-06 14:11:44.717'
DECLARE @ENDDATE DATETIME
SET @ENDDATE = '2015-01-08 00:15:00.717'
SELECT DATEDIFF(DAY, @STARTDATE, @ENDDATE) + 1
gives result as 3 days
Posted Jan 7, 2015, 7:23 PM EST
Can any one tick my answer as correct answer?
Thanks for valuable suggestions.
Hemant SrivastavaRank #581 · 4.2K reputationPosted Jan 8, 2015, 5:10 AM EST
Posted Jan 8, 2015, 7:16 AM EST
I am unable to close this thread? Why I dont know? Please help me.
Deepak VermaRank #672 · 3.6K reputationPosted Jan 12, 2015, 8:47 PM EST
You can't Accept your own answer by functionality. Only you can do is to accept the answer provided by other user which is more helpful to you (if any). It'll motivate users providing answers and indirectly help users looking for answers, like you.