ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • MSSQL GETDATE 사용예시
    IT/MS-SQL 2019. 1. 15. 09:09
    반응형

    --Getdate()

    Select Getdate()


    --YYYY/MM/DD

    Select Convert(varchar(10),Getdate(),111)


    --YYYYMMDD

    Select Convert(varchar(10),Getdate(),112)


    --HH:MM:SS

    Select Convert(varchar(8),Getdate(),108)


    --HH:MM:SS:mmm

    Select Convert(varchar(12),Getdate(),114)


    --HHMMSS

    Select Replace(Convert(varchar(8),Getdate(),108),':','')


    --HHMMSSmmm

    Select Replace(Convert(varchar(12),Getdate(),114),':','')


    --YYYY/MM/DD HH:MM:SS

    Select Replace(Convert(varchar(30),Getdate(),120),'-','/')


    --YYYY/MM/DD HH:MM:SS

    Select Replace(Convert(varchar(30),Getdate(),121),'-','/')


    --YYYY/MM/DD HH:MM:SS

    Select Convert(varchar(10),Getdate(),111) + Space(1) + Convert(varchar(8),Getdate(),108)


    --YYYYMMDDHHMMSS

    Select Convert(varchar(10),Getdate(),112) + Replace(Convert(varchar(8),Getdate(),108),':','')



    DECLARE @M CHAR(6),

    SET @M = CONVERT(CHAR(6), DATEADD(M, -1, GETDATE()), 112)

    CONVERT(CHAR(6), DATEADD(M, -1, GETDATE()), 112)

    CONVERT(CHAR(6), DATEADD(M, -2, GETDATE()), 112)

    CONVERT(CHAR(6), DATEADD(M, -3, GETDATE()), 112)


    SELECT CONVERT(CHAR(6), GETDATE(), 112)

    SELECT CONVERT(CHAR(6), DATEADD(M, -1, GETDATE()), 112)

    SELECT CONVERT(CHAR(6), DATEADD(M, -2, GETDATE()), 112)

    SELECT CONVERT(CHAR(6), DATEADD(M, -3, GETDATE()), 112)


    SELECT DATEADD(MONTH, 4, CAST(@DateFr+'01' AS DATE))

    SELECT CONVERT(CHAR(6), DATEADD(MONTH, 4, @DateFr+'01'), 112)


    반응형

    'IT > MS-SQL' 카테고리의 다른 글

    UNION / UNION ALL / EXCEPT / INTERSECT  (0) 2019.04.24
    SQL Server Profiler  (0) 2019.04.24

    댓글

Designed by Tistory.