August 30, 2017 at 8:35 am
In the following code I was expecting the Minutes from the base date but it does from midnight - is it ignoring the date component?
DECLARE @t TIME = GETDATE();
SELECT DATEDIFF(MINUTE, 0, @t)
Thanks,
Jason
August 30, 2017 at 8:54 am
What do you mean by "base date"? Also, I'm a bit confused by the your question and the defined: DATEDIFF(MINUTE, 0, @t), which does get the minutes from 0 (meaning midnight) to the current time. As far as I can tell, it works...I got 528 a few minutes ago when I ran your query, which is correct for the number of minutes from midnight until I ran the query. For example, it's 8:50 AM right now, so that would be 8 * 60 + 50, which is 530.
???? More details are needed if this doesn't "answer" your question.
Alan H
MCSE - Data Management and Analytics
Senior SQL Server DBA
Best way to ask a question: http://www.sqlservercentral.com/articles/Best+Practices/61537/
August 30, 2017 at 9:02 am
You are taking Time component of getdate() in @t, so obvious it will ignore the date part. with this script you'll get the minute difference from midnight only. Elaborate the question
August 30, 2017 at 10:27 am
Jason Toews - Wednesday, August 30, 2017 8:35 AMIn the following code I was expecting the Minutes from the base date but it does from midnight - is it ignoring the date component?
DECLARE @t DATETIME = GETDATE();
SELECT DATEDIFF(MINUTE, 0, @t)Thanks,
Jason
There FTFY.
You need to give a date if you want minutes from base date instead of minutes from midnight.
Maybe this would make it clear.
DECLARE @t TIME = GETDATE();
SELECT CAST( @t AS datetime);
August 30, 2017 at 10:32 am
If by "Base Date", you mean 0... 0 is shorthand for 19-01-01 00:00:00.000... aka midnight of 1/1/1900.
So DECLARE @t TIME = GETDATE(); SELECT DATEDIFF(MINUTE, 0, @t); is going to calculate the number of minutes between 19-01-01 00:00:00.000 and 19-01-01 12:32:15.083.
August 30, 2017 at 12:12 pm
Sorry my question could be better - I was thinking that I should be getting the minutes from 1/1/1900 not just midnight. For some reason my brain totally glossed over.
Thanks,
Jason
August 30, 2017 at 12:38 pm
Jason Toews - Wednesday, August 30, 2017 12:12 PMSorry my question could be better - I was thinking that I should be getting the minutes from 1/1/1900 not just midnight. For some reason my brain totally glossed over.Thanks,
Jason
No worries. Happens to the best of us. 😉
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply