Number of days between two given dates

杀马特。学长 韩版系。学妹 提交于 2019-12-08 06:50:53

问题


How do I calculate number of days between the to dates strictly using HQL alone.

supposing Current_Date and Expiry_Date are two dates fetched from database. I want to calculate days between Current_Date and Expiry_Date.

Also, How will I handle, if any of the value is null ?


回答1:


DECLARE @startdate datetime2 = '2013-12-05 12:10:09.3312722';
DECLARE @enddate datetime2 = '2013-12-04 12:10:09.3312722'; 
SELECT DATEDIFF(day, isnull(@startdate,GetDate()), isnull(@enddate,GetDate()));



回答2:


I figured an solution for my issue.

(extract(doy from bp.qhrIqamaexpirDate)-extract(doy from now()))

doy represents The day of the year (1 - 365/366).

bp.qhrIqamaexpirDate : 2013-02-28 00:00:00.0

now() : 2013-03-14 14:53:12.051562

extract(doy from  bp.qhrIqamaexpirDate) : 59, extract(doy from now()) : 73


来源:https://stackoverflow.com/questions/15403544/number-of-days-between-two-given-dates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!