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
 Transact-SQL (2000)
 Change the DATETIME format in MS SQL

Author  Topic 

lcpx
Yak Posting Veteran

54 Posts

Posted - 2005-11-24 : 06:01:34
In SQL server, how can I change the format of datetime, like TRUNC() in oracle

For instance, we have a table, the format of the datetime is like: 2005-11-24 00:00:00.000

I would like to change it to: 2005-11-24

Can anybody tell me which function I am supposed to use, appreciate greatly for your help!

surendrakalekar
Posting Yak Master

120 Posts

Posted - 2005-11-24 : 06:10:14
Select Convert(varchar(10),'2005-11-24 00:00:00.000')



Surendra
Go to Top of Page

lcpx
Yak Posting Veteran

54 Posts

Posted - 2005-11-24 : 06:17:40
quote:
Originally posted by surendrakalekar

Select Convert(varchar(10),'2005-11-24 00:00:00.000')



Surendra



Hi thanks for your help!

But I don’t want to convert it to varchar, I still want it to be as datatime value, because I need to compare the date with other tables.
Go to Top of Page

surendrakalekar
Posting Yak Master

120 Posts

Posted - 2005-11-24 : 06:27:00
If you want to compare why you are formating it.
Just go through "Date and Time Functions" or use "=, >, < BETWEEN, IN" ..... don't worry about the format.

Surendra
Go to Top of Page

lcpx
Yak Posting Veteran

54 Posts

Posted - 2005-11-24 : 06:32:44
because I want to display the data in a web form, and our users they don't like '2005-11-24 00:00:00.000' because it doesn't make any sense to them, they prefer '2005-11-24'

In orcle it's very easy to do that, just use TRUNC(), what I am asking is are there any similiar funtions in MS SQL?

Thanks very much!
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-11-24 : 06:59:52
In ASP format it to yyyy-mm-dd format and show the data

Madhivanan

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

sachinsamuel
Constraint Violating Yak Guru

383 Posts

Posted - 2005-11-24 : 07:25:54

If its just to display the date and not to compare then what's wrong with

quote:


Select Convert(varchar(10),'2005-11-24 00:00:00.000')




Don't sit back because of failure. It will come back to check if you still available. -- Binu
Go to Top of Page
   

- Advertisement -