Escena aplicable:
La función DATEADD () suma o resta el intervalo de tiempo especificado de la fecha.
Formato de sintaxis:
DATEADD (datepart, number, date)
descripción del campo : el parámetro de fecha es una expresión de fecha válida. número es el número de intervalos que desea agregar;
Valores de parámetro de datepart disponibles:
datepart | abreviatura |
---|---|
año | yy, yyyy |
Trimestral | qq, q |
mes | mm, m |
Día del año | dy, y |
día | dd, d |
semana | wk, ww |
semana | dw, w |
hora | S.S |
minuto | mi, n |
segundo | ss, s |
milisegundo | em |
sutil | mcs |
Nanosegundo | ns |
Ejemplos:
seleccione getdate (); - muestra la hora del sistema
seleccione dateadd (aa, 2, getdate ()); - agregue 2 años a la hora del sistema
seleccione dateadd (mm, 2, getdate ()); - agregue 2 meses a la hora del sistema
seleccione dateadd (dd, 2, getdate ()); - agregue 2 días en la hora del sistema
seleccione dateadd (ww, 2, getdate ()); - agregue 2 semanas a la hora del sistema
seleccione dateadd (hh, 2, getdate ()); - agregue 2 horas a la hora del sistema
seleccione dateadd (mi, 2, getdate ()); - agregue 2 minutos a la hora del sistema