user42348
user42348

Reputation: 4319

To change date format in sql

I have date in mm/dd/yyyy format in database.I want to display in form as dd/mm/yyyy. Can anybody help?I want to get time along with date.

Upvotes: 1

Views: 17670

Answers (3)

Jeff Olson
Jeff Olson

Reputation: 329

CONVERT(VARCHAR(10), YourField, 103)

Per your comment - you want the time as well.


select (CONVERT(VARCHAR(10), YourField, 103) + ' ' + CONVERT(VARCHAR(15), YourField, 108)) as DateTime

http://msdn.microsoft.com/en-us/library/aa226054.aspx

Upvotes: 2

Brettski
Brettski

Reputation: 20121

What Guffa said, plus this from books online: http://msdn.microsoft.com/en-us/library/aa226054.aspx

CONVERT(VARCHAR(10), column, 103)

103 is yyyy
3 is yy

Upvotes: 0

Guffa
Guffa

Reputation: 700910

A date value doesn't have a format at all. It gets it's format when you convert it to a string.

You can use the convert function to convert the value in the database, but you should rather leave that to the code in the user interface.

Upvotes: 1

Related Questions