Click here to Skip to main content
15,892,809 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
sql display is 4/7/2010 12:00:00 AM
and i want to call it in label in format "dd/mm/yy"
Posted

The best place to do the formatting is on the client side so I wouldn't format the data in the database query. Instead, after fetching the data the item containing the date could be converted to a string with the requested format.

Consider the following code
C#
string formattedDate = System.DateTime.Now.ToString(@"dd\/MM\/yy");

In place of the DateTime.Now would be your date column value
 
Share this answer
 
Comments
aarif moh shaikh 12-Sep-15 8:18am    
agree with you..
SQL Server enables custom date and time formatting via using: CAST and CONVERT (Transact-SQL)[^] function.
 
Share this answer
 
You can try this -

declare @date datetime=getdate();
select LEFT(convert(varchar(10), @date, 103),6) + Right(Year(@date),2)

keep in mind that this will return in string format.
 
Share this answer
 
if you want get date from DB as (13/09/2015) or (13/09/15)
you need to use this SQL script

SQL
SELECT CONVERT(nvarchar(10), getdate(), 103) --// 13/09/2015
--or
SELECT CONVERT(nvarchar(10), getdate(), 3) --//  13/09/15
--or
SELECT CONVERT(nvarchar(10), dateColumn, 3) from TableName
 
Share this answer
 
v5

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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