The following code sample shows how to format dates in Sql server
Dates: ------
select CONVERT(varchar,getdate(),100) ---May 23 2008 10:34AM select CONVERT(varchar,getdate(),101) ---mm/dd/yyyy select CONVERT(varchar,getdate(),103) ----dd/mm/yyyy select CONVERT(VarChar, GETDATE(), 104) ---23.05.2008 select CONVERT(varchar,GETDATE(),108) ---'hh:mm:ss', select CONVERT(varchar,GETDATE(),114) ---'hh:mm:ss:mmm', select CONVERT(varchar,GETDATE(),113) ----'dd Mmm yyyy hh:mm:ss:mmm' select cast(convert(varchar(8),getdate()-1,1) as datetime) ----2008-05-22 00:00:00.000 select getdate() ---2008-05-23 10:44:09.113 SELECT CONVERT(varchar, getdate(), 1) ------05/23/08 SELECT CONVERT(varchar, getdate(), 2) ------08.05.23 SELECT CONVERT(varchar, getdate(), 3) ------23/05/08 SELECT CONVERT(varchar, getdate(), 4) ---23.05.08 SELECT CONVERT(varchar, getdate(), 5) ----------23-05-08 SELECT CONVERT(varchar, getdate(), 6) --------23 May 08
|
| Author: Kapil Dhawan 17 Jun 2008 | Member Level: Gold Points : 2 |
Hello Nice piece of code Thanks for sharing your knowledge with us. I hope to see more good code from your side This code will help lots of guys Thanks to you Regards, Kapil
|
| Author: raja 24 Jul 2008 | Member Level: Bronze Points : 0 |
Hello
Thanks for sharing your knowledge with us.
Regards, Raja.v
|