dates

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revisionBoth sides next revision
dates [2018/05/13 14:46] – [SQL Server] daviddates [2018/05/13 14:55] david
Line 19: Line 19:
 </code> </code>
  
 +<code sql>
 +SELECT GetDate()                                                               AS [Now_datetime],
 +     --2005 (and after)
 +       DateAdd(DAY,   DateDiff(day,   0, GetDate()), 0)                        AS [today_whole_date],
 +       DateAdd(DAY,   -1, DateAdd(day,   DateDiff(day,   0, GetDate()), 0))    AS [yesterday],
 +       DateAdd(DAY,    1, DateAdd(day,   DateDiff(day,   0, GetDate()), 0))    AS [tomorrow],
 +       DateAdd(MONTH, DateDiff(month, 0, GetDate()), 0)                        AS [start of month],
 +       DateAdd(DAY,   -1, DateAdd(month, DateDiff(month, 0, GetDate()), 0))    AS [end of last month],
 +       DateAdd(MONTH, -1, DateAdd(month, DateDiff(month, 0, GetDate()), 0))    AS [start of last month],
 +       DateAdd(MONTH, -3, DateAdd(month, DateDiff(month, 0, GetDate()), 0))    AS [start of 3 months ago],
 +     --2008 (and after)
 +       EOMonth(GetDate())                                                      AS [EOM end of this month],
 +       EOMonth(GetDate(),-1)                                                   AS [EOM end of last month],
 +       DateAdd(DAY,1,EOMONTH(GetDate(),-1))                                    AS [EOM start of this month],
 +     --2014 (and after) -- At last we have DATE as datatype (whole day)
 +       CAST(GetDate()AS DATE)                                                  AS [today_whole_date_as_date],
 +    CAST(GetDate() - 1 AS DATE)                                             AS [date_cast_yesterday],
 +       DateFromParts(2017, 01, 01)                                             AS [DFP code a date],
 +       DateAdd(MONTH, -1, DateFromParts(YEAR(GetDate()), MONTH(GetDate()), 1)) AS [DFP Start of last month],
 +       DateAdd(MONTH, -2, DateFromParts(YEAR(GetDate()), MONTH(GetDate()), 1)) AS [DFP Start of month before],
 +       DateAdd(DAY,   -1, DateFromParts(YEAR(GetDate()), MONTH(GetDate()), 1)) AS [DFP End of last month]
 +;
 +</code>
 ====== Oracle ====== ====== Oracle ======
 Links of interest: Links of interest:
  • dates.txt
  • Last modified: 2021/01/12 21:08
  • by 127.0.0.1