Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how can i show by SELECT QUERY a saved date in sqlserver in dd/mm/yyyy format ???

pls help ..thanks in advance
Posted

1 solution

DateTime field stores numeric value. So, format is not important, because it's used for visualize data.

To change format of viewed date, use:
SQL
SET DATEFORMAT ymd;
SET DATEFORMAT dmy;
SET DATEFORMAT mdy;


More about: DATETIME[^], SET DATEFORMAT[^], CAST and CONVERT[^]

SQL
DECLARE @myDate DATETIME
SET @myDate = '2013-03-07'
--USA: mm/dd/yy
SELECT CONVERT(NVARCHAR(30), @myDate, 101) AS [Formated Date]

--British/French:dd/mm/yy
SELECT CONVERT(NVARCHAR(30), @myDate, 103) AS [Formated Date]

--USA: mm-dd-yy
SELECT CONVERT(NVARCHAR(30), @myDate, 110) AS [Formated Date]

--JAPAN: yy/mm/dd
SELECT CONVERT(NVARCHAR(30), @myDate, 111) AS [Formated Date]
 
Share this answer
 
v3
Comments
sr_24 7-Mar-13 6:38am    
u mean i have to alter my table ??????
sr_24 7-Mar-13 6:40am    
I only want to write a Select Query to display date in dd/mm/yyyy format ,though datetype in db is -- DateTime()

what should i do in select query ?
Maciej Los 7-Mar-13 8:47am    
No! You don't need to alter/update table.

Please, follow the llinks.
RedDk 7-Mar-13 12:17pm    
I'm not a big link follower either ... Try all these:
SELECT CONVERT (time, SYSDATETIME()) AS [SYSDATETIME()]
,CONVERT (time, SYSDATETIMEOFFSET()) AS [SYSDATETIMEOFFSET()]
,CONVERT (time, SYSUTCDATETIME()) AS [SYSUTCDATETIME()]
,CONVERT (time, CURRENT_TIMESTAMP) AS [CURRENT_TIMESTAMP]
,CONVERT (time, GETDATE()) AS [GETDATE()]
,CONVERT (time, GETUTCDATE()) AS [GETUTCDATE()];

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900