Calculates a new date, time, or datetime value by rounding the provided value up or down to the nearest multiple of the specified value with the specified granularity.
DATEROUND (date-part, datetime-expression [,multiple-expression] )
date part The date part to be added to the date.
The following date parts are not compatible with DATEROUND:
DayofYear
WeekDay
CalYearofWeek
CalWeekofYear
CalDayofWeek
For a complete listing of date parts, see Date part values.
datetime-expression The date, time, or date-time expression containing the value you are evaluating.
multiple-expression (Optional). A nonzero positive integer value expression specifying how many multiples of the units specified by the date_part parameter to use within the calculation. For example, you can use multiple-expression to specify that you want to regularize your data to 10-minute intervals. Note that if multiple-expression evaluates to zero, evaluates to a negative number, or is an explicit NULL constant, then IQ generates an error. If multiple-expression evaluates to a NULL, then the function result is NULL.
The following statement returns the value August 13, 2009, 10:30.000AM:
SELECT DATEROUND( MI, 'August 13, 2009 10:33.123AM', 10) FROM iq_dummy
This function calculates a new date, time, or datetime value by rounding the provided value up or down to the nearest value with the specified granularity. If you include the optional multiple-expression parameter, then the function rounds the date and time to the nearest specified multiple of the specified granularity.
The data type of the calculated date and time matches the data type of the multiple-expression parameter.
If you specify a multiple-expression for the millisecond, second, minute, or hour date parts, IQ assumes that the multiple applies from the start of the next larger unit of granularity:
Multiples of millisecond start from the current second
Multiples of second start from the current minute
Multiples of minute start from the current hour
Multiples of hour start from the current day
For example, if you specify a multiple of two minutes, IQ applies two minute intervals starting at the current hour.
For the millisecond, second, minute, and hour date parts, specify a multiple-expression value that divides evenly into the range of the specified date part:
For milliseconds, the valid multiple-expression values are: 1, 2, 4, 5, 8, 10, 20, 25, 40, 50, 100, 125, 200, 250, 500, 1000
For seconds and minutes, the valid multiple-expression values are: 1, 2, 3, 4, 5, 6, 10, 12, 15, 20, 30, 60
For hours, the valid multiple-expression values are: 1, 2, 3, 4, 6, 8, 12, 24
If you specify a multiple-expression for the day, week, month, quarter, or year date parts, IQ assumes the intervals started at the smallest date value (0000-01-01), smallest time value (00:00:00.000000), or smallest date-time value (0000-01-01.00:00:00.000000). For example, if you specify a multiple of 10 days, then Sybase IQ calculates 10-day intervals starting at 0000-01-01.
For the day, week, month, quarter, or year date parts, you need not specify a multiple that divides evenly into the next larger unit of time granularity.
If IQ rounds to a multiple of the week date part, then the date value is always Sunday.