Showing posts with label date n time in sqlserver. Show all posts
Showing posts with label date n time in sqlserver. Show all posts

18 April 2012

Get current date n time in sqlserver

select current_timestamp
go
select {fn now()}
go
select getdate()
go
select convert(varchar,getdate(),101)*
go
sqlserver2005 -- select convert(varchar(8),getdate(),108), convert(varchar(8),getdate(),101) 
sqlserver2008 -- select convert(time,getdate()), convert(date,getdate(),101)

 *Each style will give the output of the date in a different format.
The default style it uses is 100.
The style values can be ranging between 100-114, 120, 121, 126, 127, 130 and 131 or 0 to 8, 10, 11, 12 and 14 in this case century part will not returned.