February 27, 2020 at 6:16 pm
From my experience it is safe to use something like:
dateColumn >= '20200101' AND dateColumn < '20210101'
for any DATE/DATETIME of 2020 dates instead of dateColumn BETWEEN ...
plus those strings of dates without dashes 'yyyymmdd' (style 112) is preferred to me 🙂
and in dim.Time (DWH for later OLAP) I prefer to have time_key as INT in form of YEAR*10000+MONTH*100+DAY.
just sharing ... do not bit me much 😉
March 4, 2020 at 8:02 am
Accidentally there is mistake while explaining syntax of datediff
Please refer below in bold letters
The syntax for the DATEDIFF function is as follows:
DATEADD(DATEPART, STARTDATE, ENDDATE)
The arguments accepted by the DATEADD function are as follows:
March 4, 2020 at 3:50 pm
Just my humble opinion but, except for the fact that the newer datatypes can use fewer bytes, they pretty much suck for me because you cannot do direct data math with them, which is non-ANSI/ISO compliant. The standards do say that EndDate-StartDate = Period and StartDate+Period = EndDate, etc.
Microsoft apparently realized the boo-boo they made because of all the people wanking about not being able to easily calculate periods to the millisecond but instead of fixing the real problem, they introduced DATEDIFF_BIG.
As for the EOMONTH function, I'd have much rather had an FOMONTH function that would return a DATETIME datatype.
So far as dates prior to 01 Jan 1753, I wouldn't use SQL Server for them if I needed to work with them because of all the calendar changes made prior to that date. In other words, the dates are actually incorrect prior to that date depending on which country and religion you're working with.
--Jeff Moden
Change is inevitable... Change for the better is not.
March 11, 2020 at 7:24 pm
Just a quick comment re. DateAdd. I just got myself into trouble with a DateAdd function that was adding 1 year to 2/28/2019. The application was working with budgets that had a variety of end dates, with each end date always the last day in the month. We've used this application for a couple years now with no issue. Then along comes the leap year in 2020! Dateadd(year,1,'2/28/19') will return 2/28/2020. That makes sense - but it's not the end of the month! The fix is easy with an EOMONTH check, and maybe this audience won't be silly enough to forget about leap years but.....!!
March 11, 2020 at 11:14 pm
Just a quick comment re. DateAdd. I just got myself into trouble with a DateAdd function that was adding 1 year to 2/28/2019. The application was working with budgets that had a variety of end dates, with each end date always the last day in the month. We've used this application for a couple years now with no issue. Then along comes the leap year in 2020! Dateadd(year,1,'2/28/19') will return 2/28/2020. That makes sense - but it's not the end of the month! The fix is easy with an EOMONTH check, and maybe this audience won't be silly enough to forget about leap years but.....!!
EOMONTH does make the fix easy... provided that your column data doesn't also store times other than midnight.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 5 posts - 16 through 19 (of 19 total)
You must be logged in to reply to this topic. Login to reply