Click here to Skip to main content
15,892,480 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a table name "tbemployee" with fields id, empName, Joiningdate.(in sql server)
i have declared my Joiningdate column as DATETIME type,

when i want to display the records on asp.net webform, i write the COMMAND as: SELECT * FROM tbemployee,

it displays the record...... but the date format is in mm/dd/yyyy hh:mm:ss

now my question is..... how i can display the date in dd/MM/yyyy

What I have tried:

SELECT * FROM tbemployee
Actually I'm displaying the record in gridview in asp.net
Posted
Updated 14-May-17 6:28am

You convert it when you want to display it using ToString("dd/MM/yyyy"). We don't know how you are reading the data or displaying it so it's hard to say specifically but if it is from a data reader then it'll be

string dt = ((DateTime)dataReader["Joiningdate"]).ToString("dd/MM/yyyy");


If you are binding the field in a gridview or something then you can normally specify the format via the control you're binding to.
 
Share this answer
 
Comments
Member 13188865 14-May-17 12:19pm    
binding in Gridview
Please, tell me the solution.
F-ES Sitecore 15-May-17 9:47am    
http://stackoverflow.com/questions/7235324/datetime-format-in-asp-net-gridview

Google "asp.net gridview format date" for plenty more examples.
Try:
SQL
SELECT MyFirstColumn, CONVERT(NVARCHAR(10), JoiningDate, 103) AS [Date], MyLastColumn FROM tbEmployee;
 
Share this answer
 

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