mirror of
https://github.com/FirebirdSQL/firebird.git
synced 2025-01-22 20:03:02 +01:00
Enable WEEK for dateAdd and dateDiff.
This commit is contained in:
parent
ce66b6051a
commit
3d750c2bf1
@ -11,6 +11,7 @@ Authors:
|
||||
Adriano dos Santos Fernandes <adrianosf@uol.com.br>
|
||||
Oleg Loa <loa@mail.ru>
|
||||
Alexey Karyakin <aleksey.karyakin@mail.ru>
|
||||
Claudio Valderrama C. <cvalde at usa.net>
|
||||
|
||||
|
||||
---
|
||||
@ -290,17 +291,16 @@ Format:
|
||||
DATEADD( <number> <timestamp_part> TO <date_time> )
|
||||
DATEADD( <timestamp_part>, <number>, <date_time> )
|
||||
|
||||
timestamp_part ::= { YEAR | MONTH | DAY | HOUR | MINUTE | SECOND | MILLISECOND }
|
||||
timestamp_part ::= { YEAR | MONTH | DAY | WEEK | HOUR | MINUTE | SECOND | MILLISECOND }
|
||||
|
||||
Notes:
|
||||
1) WEEKDAY and YEARDAY cannot be used. It doesn't make sense.
|
||||
2) YEAR, MONTH and DAY could not be used with time values.
|
||||
3) All timestamp_part values could be used with timestamp values.
|
||||
4) When using hour, minute, second and millisecond for DATEADD and dates, the quantity added or
|
||||
substracted should account at least for one day to produce effect (IE adding 23 hours to a date
|
||||
subtracted should account at least for one day to produce effect (IE adding 23 hours to a date
|
||||
doesn't increment it).
|
||||
|
||||
|
||||
Example:
|
||||
select dateadd(-1 day for current_date) as yesterday
|
||||
from rdb$database;
|
||||
@ -318,7 +318,7 @@ Format:
|
||||
DATEDIFF( <timestamp_part> FROM <date_time> TO <date_time> )
|
||||
DATEDIFF( <timestamp_part>, <date_time>, <date_time> )
|
||||
|
||||
timestamp_part ::= { YEAR | MONTH | DAY | HOUR | MINUTE | SECOND | MILLISECOND }
|
||||
timestamp_part ::= { YEAR | MONTH | DAY | WEEK | HOUR | MINUTE | SECOND | MILLISECOND }
|
||||
|
||||
Notes:
|
||||
1) Returns positive value if the second value is greater than the first one,
|
||||
@ -328,6 +328,10 @@ Notes:
|
||||
4) YEAR, MONTH and DAY could not be used with time values.
|
||||
5) All timestamp_part values could be used with timestamp values.
|
||||
|
||||
Example:
|
||||
select datediff(week from cast('yesterday' as timestamp) - 7 to current_timestamp)
|
||||
from rdb$database;
|
||||
|
||||
|
||||
------
|
||||
DECODE
|
||||
|
@ -1301,6 +1301,8 @@ static dsc* evlDateAdd(Jrd::thread_db* tdbb, const SysFunction* function, Jrd::j
|
||||
|
||||
switch (part)
|
||||
{
|
||||
// TO DO: detect overflow in the following cases.
|
||||
|
||||
case blr_extract_year:
|
||||
{
|
||||
times.tm_year += quantity;
|
||||
@ -1357,11 +1359,9 @@ static dsc* evlDateAdd(Jrd::thread_db* tdbb, const SysFunction* function, Jrd::j
|
||||
timestamp.value().timestamp_date += quantity;
|
||||
break;
|
||||
|
||||
//case blr_extract_week:
|
||||
// timestamp.value().timestamp_date += quantity * 7;
|
||||
// break;
|
||||
|
||||
// TO DO: detect overflow in the following cases.
|
||||
case blr_extract_week:
|
||||
timestamp.value().timestamp_date += quantity * 7;
|
||||
break;
|
||||
|
||||
case blr_extract_hour:
|
||||
if (valueDsc->dsc_dtype == dtype_sql_date)
|
||||
@ -1510,7 +1510,7 @@ static dsc* evlDateDiff(Jrd::thread_db* tdbb, const SysFunction* function, Jrd::
|
||||
case blr_extract_year:
|
||||
case blr_extract_month:
|
||||
case blr_extract_day:
|
||||
//case blr_extract_week:
|
||||
case blr_extract_week:
|
||||
if (value1Dsc->dsc_dtype == dtype_sql_time || value2Dsc->dsc_dtype == dtype_sql_time)
|
||||
status_exception::raise(isc_expression_eval_err, 0);
|
||||
break;
|
||||
@ -1559,9 +1559,9 @@ static dsc* evlDateDiff(Jrd::thread_db* tdbb, const SysFunction* function, Jrd::
|
||||
result = timestamp2.value().timestamp_date - timestamp1.value().timestamp_date;
|
||||
break;
|
||||
|
||||
//case blr_extract_week:
|
||||
// result = (timestamp2.value().timestamp_date - timestamp1.value().timestamp_date) / 7;
|
||||
// break;
|
||||
case blr_extract_week:
|
||||
result = (timestamp2.value().timestamp_date - timestamp1.value().timestamp_date) / 7;
|
||||
break;
|
||||
|
||||
// TO DO: detect overflow in the following cases.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user