Only Time in SQL SERVER
(1 row(s) affected)
Post Reference: Vikram Aristocratic Elfin Share
Many a time we just need to store time part of date only, but when we look
after SQL Server there is no such datatype which allow us to store only time
part of the datetime.
So the question of the matter is how to store only time in sql table
object. Here is a small exmple of storing time efficiently, is to use an
integer column.
create table demoToStoreOnlyTime_tab(
myTotalHour smallint)
Command(s) completed successfully.
Now while inserting, you multiply the number of hours by 100, and add the
minutes
insert into demoToStoreOnlyTime_tab values( 100*datepart(hour,getdate()) + datepart(minute,getdate()))
(1 row(s) affected)
Rest let the developer do there work for formating while displaying time on
front end
select CAST(LEFT(myTotalHour, LEN(myTotalHour)-2) + ':'+ RIGHT(myTotalHour, 2) AS VARCHAR(5)) as 'MyHour' from demoToStoreOnlyTime_tab
MyHour
------
11:16
Happy Coding :)
plz give time format like as hhmi
ReplyDelete