Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Date Format on Query

Author  Topic 

vicpal25
Starting Member

21 Posts

Posted - 2007-04-24 : 13:15:43
How can I format the following query to output "mm/dd/yyyy"

SELECT pEff_Dt FROM IM_Costing,IM_Demographics WHERE IM_Costing.pIM_Loc='BLA' AND IM_Costing.pItem_ID=IM_Demographics.pItem_ID AND IM_Demographics.Item_No=@v_assyno

I tried:

SELECT convert(datetime, pEff_Dt, 101) FROM IM_Costing,IM_Demographics WHERE IM_Costing.pIM_Loc='BLA' AND IM_Costing.pItem_ID=IM_Demographics.pItem_ID AND IM_Demographics.Item_No=@v_assyno

But that didnt work. Any suggestions?

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-04-24 : 13:18:26
you should do

SELECT convert(varchar, pEff_Dt, 101) FROM IM_Costing,IM_Demographics WHERE IM_Costing.pIM_Loc='BLA' AND IM_Costing.pItem_ID=IM_Demographics.pItem_ID AND IM_Demographics.Item_No=@v_assyno




************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-04-24 : 13:18:38
It is recommended that you don't do this in your query. It is better to format your data in your application.

When you format your datetimes in T-SQL, you no longer are returning datetime data but rather character data.


Tara Kizer
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-04-24 : 13:19:28
quote:
Originally posted by tkizer

It is recommended that you don't do this in your query. It is better to format your data in your application.

When you format your datetimes in T-SQL, you no longer are returning datetime data but rather character data.


Tara Kizer
http://weblogs.sqlteam.com/tarad/



Ofcouse I totally agree with Tara on that. If you can move the pretty-formatting to the front end, do it.


************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

vicpal25
Starting Member

21 Posts

Posted - 2007-04-24 : 13:28:42
Yeah, thats was I was first trying to implement but I am having difficulties with ADO.NET and binding to a Dataset with this value.
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2007-04-24 : 14:20:00
vicpal -- if you are using .NET, all the more reason to do the formatted there -- it is very, very easy if you return native datetimes values from your database.

If you are having difficulties, please explain and we can help you out. Certainly converting everything to a VARCHAR instead of returning DateTimes shouldn't make anything easier for you or solve other issues you might be having.

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-04-30 : 10:34:42
quote:
Originally posted by vicpal25

Yeah, thats was I was first trying to implement but I am having difficulties with ADO.NET and binding to a Dataset with this value.


Was I right in saying "Users dont know how to format dates in front end instead they simply ask here on how to do it using sql"?


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -