SQL SERVER – Get Time in Hour:Minute Format from a Datetime – Get Date Part Only from Datetime

I have seen scores of expert developers getting perplexed with SQL Server in finding time only from datetime datatype. Let us have a quick glance look at the solution. Let us learn about how to get Time in Hour:Minute Format from a Datetime as well as to get Date Part Only from Datetime.

Additionally, if you want to get current datetime you can use following functions in place of datetime variable.

CURRENT_TIMESTAMP is a nondeterministic function. Views and expressions that reference this column cannot be indexed. CURRENT_TIMESTAMP can be used to print the current date and time every time that the report is produced. GETDATE is a nondeterministic function. Views and expressions that reference this column cannot be indexed. GETDATE can be used to print the current date and time every time that the report is produced.

Please leave a comment about Hour:Minute Format. I will be happy to read them.

I wanted to be able to format dates in a similar way to the VB6 FORMAT() function where you give it a date and a picture of the date and it returns a string in that format. I have written this as a SQL function and use it quite often

Hi, I’ve tryed to use this but it doesn’t function, it appears a message saying: “Type TIME is not a defined system type.”, also if I use the date, I need to compare with the BETWEEN in hours and it doesn’t function, but if I put the date (for example “BETWEEN ’04/04/2015′ AND ’04/05/2015′ “) the query give a result, but if I use “BETWEEN ’06:00:00.000′ AND ’20:00:00.000′ ” it doesn’t show any result, can anyone help please?

Pinal Dave is a SQL Server Performance Tuning Expert and an independent consultant. He has authored 11 SQL Server database books, 21 Pluralsight courses and has written over 4000 articles on the database technology on his blog at a https://blog.sqlauthority.com. Along with 16+ years of hands on experience he holds a Masters of Science degree and a number of database certifications.