ฟังก์ชันSQL Server DAYEADD()
ตัวอย่าง
เพิ่มวันที่เป็นเวลาหนึ่งปี แล้วส่งคืนวันที่:
SELECT DATEADD(year, 1, '2017/08/25') AS DateAdd;
ความหมายและการใช้งาน
ฟังก์ชัน DATEDD() เพิ่มช่วงเวลา/วันที่ให้กับวันที่แล้วส่งกลับวันที่
ไวยากรณ์
DATEADD(interval, number, date)
ค่าพารามิเตอร์
Parameter | Description |
---|---|
interval | Required. The time/date interval to add. Can be one of the following values:
|
number | Required. The number of interval to add to date. Can be positive (to get dates in the future) or negative (to get dates in the past) |
date | Required. The date that will be modified |
รายละเอียดทางเทคนิค
ทำงานใน: | SQL Server (เริ่มตั้งแต่ปี 2008), ฐานข้อมูล Azure SQL, Azure SQL Data Warehouse, Parallel Data Warehouse |
---|
ตัวอย่างเพิ่มเติม
ตัวอย่าง
เพิ่มวันที่สองเดือน แล้วส่งคืนวันที่:
SELECT DATEADD(month, 2, '2017/08/25') AS DateAdd;
ตัวอย่าง
ลบสองเดือนจากวันที่ แล้วส่งคืนวันที่:
SELECT DATEADD(month, -2, '2017/08/25') AS DateAdd;
ตัวอย่าง
เพิ่ม 18 ปีเป็นวันที่ในคอลัมน์วันเกิด จากนั้นส่งคืนวันที่:
SELECT LastName,
BirthDate, DATEADD(year, 18, BirthDate) AS DateAdd FROM Employees;