เปรียบเทียบวันที่ใน MSSQL คำสั่ง DATEDIFF()

Post date: Aug 23, 2013 3:29:21 AM

เปรียบเทียบวันที่ระหว่าง 2 วันที่ เพื่อหาจำนวนวัน

DATEDIFF(datepart,startdate,enddate)

Example

Now we want to get the number of days between two dates.

We use the following SELECT statement:

SELECT DATEDIFF(day,’2008-06-05′,’2008-08-05′) AS DiffDate

Result:

Example

Now we want to get the number of days between two dates (notice that the second date is “earlier” than the first date, and will result in a negative number).

We use the following SELECT statement:

SELECT DATEDIFF(day,’2008-08-05′,’2008-06-05′) AS DiffDate

Result:

แหล่งข้อมูล: http://www.w3schools.com/sql/func_datediff.asp และ http://www.ninenik.com/content.php?arti_id=428

DiffDate

61

DiffDate

-61