question

kgotlhaetsile avatar image
kgotlhaetsile asked

how to change a date format on query

Hi, I'm trying to change the date on this query. USE [adventureworks2008r2] GO SELECT p.Title, p.PersonType , p.NameStyle , p.FirstName , p.MiddleName , p.LastName , p.ModifiedDate, pp.PhoneNumber , pp.PhoneNumberTypeID, pe.EmailAddress, Pe.ModifiedDate FROM Person.Person AS p JOIN Person.PersonPhone AS pp ON p.BusinessEntityID = pp.BusinessEntityID Join Person.EmailAddress As Pe on p.BusinessEntityID = pe.BusinessEntityID
date-format
2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Kev Riley avatar image Kev Riley ♦♦ commented ·
Are the date fields actually datetime (or date) datatypes?
0 Likes 0 ·
Grant Fritchey avatar image Grant Fritchey ♦♦ commented ·
This site functions according to votes. For all helpful answers below, show this by clicking on the thumbs up next to those answers. If any one answer lead to a solution, indicate this by clicking on the check mark next to that answer.
0 Likes 0 ·
sp_lock avatar image
sp_lock answered
Hi You could either use [CAST][1] expression for each of the date\time fields Or the [SET DATEFORMAT][2] at the start of the query. Personal I use prefer to us CAST, especially if you are just wanting to change the output. [1]: http://msdn.microsoft.com/en-us/library/ms187928.aspx [2]: http://SET+DATEFORMAT
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

emil87b avatar image
emil87b answered
Hi, to set a date format i like to use this "cheatsheet" http://www.sql-server-helper.com/tips/date-formats.aspx
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Grant Fritchey avatar image
Grant Fritchey answered
If you have to do the formatting in T-SQL, I think @sp_lock has the answer. But, formatting is not something that T-SQL does well. Generally, I suggest that people rely on the client applications or reporting tools for formatting. They do a much better job of it.
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.