SAP Sybase IQ 16: Missing DATEROUND()
Question
I'm just wondering what might can be wrong
I was trying to round a date by its quarter. Beside some hacks I found the function DATEROUND, which I was thinking of based of documentation is able to do so. So I've build up a little test:
SELECT DATEROUND(qq, now());
which failed with
Feature 'dateround' not implemented.
Is this a bug inside documentation or did I just miss to enable something? Or is there maybe another easy solution without a case construct for getting this function?
Solution 2
Based on an answer here I got an idea and solved it for me little different. I needed it inside the column list of an select statement. $date
is representing the date-column from my table.
--SELECT ....
DATEADD(
quarter,
datepart(
quarter,
$date)-1,
dateadd(year,
datepart(year,
$date)-1000,
'1000-01-01 00:00:00')
)
--- FROM ....
Seems to work by now.
OTHER TIPS
Use the T-SQL compatible DATEPART
construct to obtain the quarter, and construct the date from that.
For instance using T-SQL on SQL Server:
SELECT CONVERT(DATETIME, CONVERT(VARCHAR(4), DATEPART(YEAR, GETDATE())) +
STUFF(
'00'
, 3 - (LEN(1+(DATEPART(QUARTER, GETDATE()) * 3) - 3))
, LEN(1+(DATEPART(QUARTER, GETDATE()) * 3) - 3)
, 1+(DATEPART(QUARTER, GETDATE()) * 3) - 3
) +
'01');
Returns 2015-01-01 00:00:00.000
, the start of the current quarter of 2015.
According to the documentation for Sybase IQ 15; you'd need to modify the above to something like (I can't check the syntax since I don't have Sybase IQ on this machine):
SELECT CONVERT(DATETIME, CONVERT(VARCHAR(4), DATEPART(YEAR, GETDATE())) +
STUFF(
'00'
, 3 - (LENGTH(1+(DATEPART(QUARTER, GETDATE()) * 3) - 3))
, LENGTH(1+(DATEPART(QUARTER, GETDATE()) * 3) - 3)
, 1+(DATEPART(QUARTER, GETDATE()) * 3) - 3
) +
'01');
See http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc38151.1510/html/iqrefbb/X315942.htm for details.