Posted By

derebus on 08/13/10


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite


Getting Dates in Sql Server 2

 / Published in: SQL


El primer dia del mes, El Ultimo dia del mes, El Lunes de la semana actual, Primer dia del año, Ultimo dia del mes anterior, Ultimo dia del año anterior, Primer lunes del mes, Primer dia del mes anterior

  1. SELECT DATEADD(mm, DATEDIFF(mm,0,GETDATE()), 0),'El primer dia del mes'
  2. UNION
  3. SELECT DATEADD(ms,-3,DATEADD(mm, DATEDIFF(m,0,GETDATE() )+1, 0)),'El Ultimo dia del mes'
  4. UNION
  5. SELECT DATEADD(wk, DATEDIFF(wk,0,GETDATE()), 0),'El Lunes de la semana actual'
  6. UNION
  7. SELECT DATEADD(yy, DATEDIFF(yy,0,GETDATE()), 0),'Primer dia del año'
  8. UNION
  9. SELECT DATEADD(ms,-3,DATEADD(mm, DATEDIFF(mm,0,GETDATE() ), 0)),'Ultimo dia del mes anterior'
  10. UNION
  11. SELECT DATEADD(ms,-3,DATEADD(yy, DATEDIFF(yy,0,GETDATE() ), 0)),'Ultimo dia del año anterior'
  12. UNION
  13. SELECT DATEADD(wk, DATEDIFF(wk,0,DATEADD(dd,6-DATEPART(DAY,GETDATE()),GETDATE())), 0),'Primer lunes del mes'
  14. UNION
  15. SELECT DATEADD(mm, -1, DATEADD(mm, DATEDIFF(mm,0,GETDATE()), 0)),'Primer dia del mes anterior'

Report this snippet  

You need to login to post a comment.