November 19, 2015 at 2:45 pm
Alvin Ramard (11/19/2015)
Eirikur Eiriksson (11/19/2015)
Alvin Ramard (11/19/2015)
Eirikur Eiriksson (11/19/2015)
Luis Cazares (11/19/2015)
I feel excluded.How come?
😎
Luis, I'll include you with me. 🙂
That looks way too close to a union all statement for comfort:-P
😎
Union all???? I didn't say I was including the rest of you! 😀
That's why there is EXCEPT:-D
😎
November 19, 2015 at 2:47 pm
Luis Cazares (11/19/2015)
Eirikur Eiriksson (11/19/2015)
Luis Cazares (11/19/2015)
I feel excluded.How come?
😎
You left my method out
Couldn't fit it in the select statement, too many EXEC'y thingies in there, any alternatives?
😎
November 19, 2015 at 2:57 pm
Let's ask a question in a SQL Server 2012 forum when it is really about Access. Oh, and I even prefaced my answer with "..., and if you are using SQL Server 2012..." and try and use it in Access and then post back that it didn't work.
November 19, 2015 at 3:04 pm
Lynn Pettis (11/19/2015)
Let's ask a question in a SQL Server 2012 forum when it is really about Access. Oh, and I even prefaced my answer with "..., and if you are using SQL Server 2012..." and try and use it in Access and then post back that it didn't work.
Did someone move the question? Looks like the Access forum to me. :ermm:
For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]
November 19, 2015 at 3:07 pm
Alvin Ramard (11/19/2015)
Lynn Pettis (11/19/2015)
Let's ask a question in a SQL Server 2012 forum when it is really about Access. Oh, and I even prefaced my answer with "..., and if you are using SQL Server 2012..." and try and use it in Access and then post back that it didn't work.Did someone move the question? Looks like the Access forum to me. :ermm:
Probably, I did send a report asking that it be moved to an Access forum.
November 19, 2015 at 3:38 pm
Cool, I just found a thread that reminds me on the Bankers Rounding Function threads.
Nice that some one else is in the flame war with this particular adversary.
November 19, 2015 at 4:48 pm
Eirikur Eiriksson (11/19/2015)
So to recap, here are 9 different methods for getting the current time, any additions anyone?😎
SELECT
GETDATE()
,SYSDATETIME()
,SYSDATETIMEOFFSET()
,CURRENT_TIMESTAMP
,SYSUTCDATETIME()
,GETUTCDATE()
,DATEADD(MILLISECOND, (@@CPU_BUSY + @@IDLE) * SQRT(64.2548),(SELECT sqlserver_start_time FROM sys.dm_os_sys_info))
,(SELECT MAX(start_time) FROM sys.dm_exec_requests)
,(SELECT DATEADD(ms,ms_ticks%1000,DATEADD(ss,ms_ticks/1000,sqlserver_start_time)) FROM sys.dm_os_sys_info)
There are many more but, just to wet the appetite for other possibilities...
SELECT {fn NOW()};
SELECT {fn CURRENT_DATE()} + ' ' + {fn CURRENT_TIME()};
EXEC xp_CmdShell 'Date /T & Time /T';
--Jeff Moden
Change is inevitable... Change for the better is not.
November 19, 2015 at 4:55 pm
Jeff Moden (11/19/2015)
Eirikur Eiriksson (11/19/2015)
So to recap, here are 9 different methods for getting the current time, any additions anyone?😎
SELECT
GETDATE()
,SYSDATETIME()
,SYSDATETIMEOFFSET()
,CURRENT_TIMESTAMP
,SYSUTCDATETIME()
,GETUTCDATE()
,DATEADD(MILLISECOND, (@@CPU_BUSY + @@IDLE) * SQRT(64.2548),(SELECT sqlserver_start_time FROM sys.dm_os_sys_info))
,(SELECT MAX(start_time) FROM sys.dm_exec_requests)
,(SELECT DATEADD(ms,ms_ticks%1000,DATEADD(ss,ms_ticks/1000,sqlserver_start_time)) FROM sys.dm_os_sys_info)
There are many more but, just to wet the appetite for other possibilities...
SELECT {fn NOW()};
SELECT {fn CURRENT_DATE()} + ' ' + {fn CURRENT_TIME()};
EXEC xp_CmdShell 'Date /T & Time /T';
That's our Jeff, bring on the ODBC conical functions. Those are so much fun when you see them for the first time.
November 19, 2015 at 6:29 pm
Lynn Pettis (11/19/2015)
Jeff Moden (11/19/2015)
Eirikur Eiriksson (11/19/2015)
So to recap, here are 9 different methods for getting the current time, any additions anyone?😎
SELECT
GETDATE()
,SYSDATETIME()
,SYSDATETIMEOFFSET()
,CURRENT_TIMESTAMP
,SYSUTCDATETIME()
,GETUTCDATE()
,DATEADD(MILLISECOND, (@@CPU_BUSY + @@IDLE) * SQRT(64.2548),(SELECT sqlserver_start_time FROM sys.dm_os_sys_info))
,(SELECT MAX(start_time) FROM sys.dm_exec_requests)
,(SELECT DATEADD(ms,ms_ticks%1000,DATEADD(ss,ms_ticks/1000,sqlserver_start_time)) FROM sys.dm_os_sys_info)
There are many more but, just to wet the appetite for other possibilities...
SELECT {fn NOW()};
SELECT {fn CURRENT_DATE()} + ' ' + {fn CURRENT_TIME()};
EXEC xp_CmdShell 'Date /T & Time /T';
That's our Jeff, bring on the ODNC conical functions. Those are so much fun when you see them for the first time.
yeah. Learned something new today.
SELECT {fn CURRENT_TIMESTAMP(0)}
SELECT {fn CONCAT({fn CURDATE( )}+' ',{fn CURTIME( )})}
-- Itzik Ben-Gan 2001
November 19, 2015 at 6:54 pm
-- TheTimeIs Script
-- start script
CREATE PROC TheTimeIs AS
SELECT CREATED FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_NAME = 'TheTimeIs';
GO
EXEC TheTimeIs;
DROP PROC TheTimeIs;
GO
-- end script
-- Itzik Ben-Gan 2001
November 20, 2015 at 1:16 am
Jeff Moden (11/19/2015)
There are many more but, just to wet the appetite for other possibilities...
SELECT {fn NOW()};
SELECT {fn CURRENT_DATE()} + ' ' + {fn CURRENT_TIME()};
EXEC xp_CmdShell 'Date /T & Time /T';
Thanks for the heads up Jeff!
Recapping again, weeding out the obviously inaccurate ones and adding some extra information
😎
USE tempdb;
GO
SET NOCOUNT ON;
;WITH DATE_TIME_METHODS(DTM_VAL,DTM_FUNCTION,DTM_DESCRIPTION) AS
(
SELECT CONVERT(DATETIMEOFFSET(7),SYSDATETIME(),0)
,'sysdatetime()' , 'T-SQL SYSDATETIME()'
UNION ALL
SELECT CONVERT(DATETIMEOFFSET(7),SYSDATETIMEOFFSET(),0)
,'sysdatetimeoffset()' , 'T-SQL SYSDATETIMEOFFSET()'
UNION ALL
SELECT CONVERT(DATETIMEOFFSET(7),SYSUTCDATETIME(),0)
,'sysutcdatetime()' , 'T-SQL SYSUTCDATETIME()'
UNION ALL
SELECT CONVERT(DATETIMEOFFSET(7),GETUTCDATE(),0)
,'getutcdate()' , 'T-SQL GETUTCDATE()'
UNION ALL
SELECT CONVERT(DATETIMEOFFSET(7),GETDATE(),0)
,'getdate()' , 'T-SQL GETDATE()'
UNION ALL
SELECT CONVERT(DATETIMEOFFSET(7),CURRENT_TIMESTAMP,0)
,'getdate()' , 'T-SQL CURRENT_TIMESTAMP'
UNION ALL
SELECT CONVERT(DATETIMEOFFSET(7),{fn NOW()},0)
,'getdate()' , 'ODBC fn NOW()'
UNION ALL
SELECT CONVERT(DATETIMEOFFSET(7),{fn CURRENT_TIMESTAMP ()},0)
,'fn current_timestamp()' , 'ODBC fn CURRENT_TIMESTAMP ()'
UNION ALL
SELECT CONVERT(DATETIMEOFFSET(7),{fn CURRENT_DATE()} + ' ' + {fn CURRENT_TIME()},0)
,'getdate()' , 'ODBC fn CURRENT_DATE() + fn CURRENT_TIME()'
UNION ALL
SELECT CONVERT(DATETIMEOFFSET(7),{fn CURDATE()} + ' ' + {fn CURTIME()},0)
,'getdate()' , 'ODBC fn CURDATE() + fn CURTIME()'
UNION ALL
SELECT CONVERT(DATETIMEOFFSET(7),(SELECT DATEADD(MILLISECOND,total_elapsed_time,start_time)
FROM sys.dm_exec_requests
WHERE session_id = @@SPID),0)
,'N/A' , 'Dynamic Management View dm_exec_requests with total_elapsed_time correction'
UNION ALL
SELECT CONVERT(DATETIMEOFFSET(7),(SELECT MAX(T.StartTime)
FROM sys.fn_trace_gettable(CONVERT(VARCHAR(150)
, ( SELECT TOP 1 FI.[value]
FROM sys.fn_trace_getinfo(NULL) FI
WHERE FI.property = 2 ),0), DEFAULT) AS T
WHERE T.SPID = @@SPID),0)
,'N/A' , 'Default Trace fn_trace_gettable'
)
SELECT
DT.DTM_VAL
,DT.DTM_FUNCTION
,DT.DTM_DESCRIPTION
FROM DATE_TIME_METHODS DT;
Output
DTM_VAL DTM_FUNCTION DTM_DESCRIPTION
---------------------------------- ---------------------- ---------------------------------------------------------------------------
2015-11-20 08:17:33.4878951 +00:00 sysdatetime() T-SQL SYSDATETIME()
2015-11-20 08:17:33.4878951 +00:00 sysdatetimeoffset() T-SQL SYSDATETIMEOFFSET()
2015-11-20 08:17:33.4878951 +00:00 sysutcdatetime() T-SQL SYSUTCDATETIME()
2015-11-20 08:17:33.4870000 +00:00 getutcdate() T-SQL GETUTCDATE()
2015-11-20 08:17:33.4870000 +00:00 getdate() T-SQL GETDATE()
2015-11-20 08:17:33.4870000 +00:00 getdate() T-SQL CURRENT_TIMESTAMP
2015-11-20 08:17:33.4870000 +00:00 getdate() ODBC fn NOW()
2015-11-20 08:17:33.4870000 +00:00 fn current_timestamp() ODBC fn CURRENT_TIMESTAMP ()
2015-11-20 08:17:33.4870000 +00:00 getdate() ODBC fn CURRENT_DATE() + fn CURRENT_TIME()
2015-11-20 08:17:33.4870000 +00:00 getdate() ODBC fn CURDATE() + fn CURTIME()
2015-11-20 08:17:33.4870000 +00:00 N/A Dynamic Management View dm_exec_requests with total_elapsed_time correction
2015-11-20 08:17:33.4870000 +00:00 N/A Default Trace fn_trace_gettable
November 20, 2015 at 2:00 am
There are many more but, just to wet the appetite for other possibilities...
Sounds a bit too damp for my liking. 'Whet' is the word I think you were looking for 🙂
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
November 20, 2015 at 5:25 am
Phil Parkin (11/20/2015)
There are many more but, just to wet the appetite for other possibilities...
Sounds a bit too damp for my liking. 'Whet' is the word I think you were looking for 🙂
HA. Good catch, Phil. @=)
November 20, 2015 at 5:57 am
Looks like the spam bomb went off this morning...
Ugh...
November 20, 2015 at 6:07 am
Nothing like staying up late two nights in a row to do releases, get called back ten minutes after the second release to be told I forgot to move scripts, and then have a brisk discussion with everyone involved to explain why those scripts didn't get moved.
ME: "Those scripts weren't on the move sheet and I don't move anything that I wasn't told to move."
Others: "But the scripts are in X folder."
ME: "Lots of scripts are in that folder. I am not going to run every script in that folder because some of them aren't ready to be moved yet. And you haven't given me a list of scripts to run, and there is nothing from the Y team indicating that there are additional scripts to run. Sorry. Not breaking production on your say so."
It wasn't quite that bad, but I'm exhausted this morning and everyone's running around here in semi-panic mode. "Where are the scripts?"
Viewing 15 posts - 51,541 through 51,555 (of 66,712 total)
You must be logged in to reply to this topic. Login to reply