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.
| Author |
Topic |
|
naidu4u
Starting Member
23 Posts |
Posted - 2010-10-05 : 22:23:00
|
| I need to convert a date of type varchar into date format but I dont need the time part in it and I am using SQL server 2000. I've tried using date function inorder to extract the date part but it dint work in SQL 2000. So, please help me in getting just the date into datetime format.select convert(varchar(10), a.dates, 101) dates from(select getdate()-5 datesunionselect getdate()-4unionselect getdate()-3unionselect getdate()-2unionselect getdate()-1union select getdate() unionselect getdate()+1unionselect getdate()+2unionselect getdate()+3unionselect getdate()+4union select getdate()+5) a my output looks likedates:09/30/201010/01/201010/02/201010/03/201010/04/201010/05/201010/06/201010/07/201010/08/201010/09/201010/10/2010 this is my query but the result which am getting is in varchar format but I need the same date in date format but with out time. I need to use this sql in my cognos report and I cant use any UDF or stored proceduresThanks in advance. |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2010-10-05 : 23:00:48
|
| I think you may be confusing "format" with "datatype". Sql server 2000 does not have a date datatype that doesn't include a time portion. There are two choices: datetime and smalldatetime. Anytime you see a date representation on screen it is a string representation of a date. Even "select getdate()" results to a the current datetime displayed on your screen in whatever "format" windows is configured to show dates.So having said that are you looking for a way to return all your dates as datetime 12:00 AM? ie: "9/30/2010 00:00:00.000" ? If so you can change your select to:select dateadd(day, datediff(day, 0, a.dates), 0)Be One with the OptimizerTG |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-10-06 : 05:29:39
|
| Where do you want to show formatted dates? If you use front end application, do formation thereMadhivananFailing to plan is Planning to fail |
 |
|
|
naidu4u
Starting Member
23 Posts |
Posted - 2010-10-06 : 10:07:08
|
| select convert(datetime, convert(varchar(10), a.dates, 101),120) dates from(select getdate()-5 datesunionselect getdate()-4unionselect getdate()-3unionselect getdate()-2unionselect getdate()-1union select getdate() unionselect getdate()+1unionselect getdate()+2unionselect getdate()+3unionselect getdate()+4union select getdate()+5) a I have tried this and this is giving me date how I wanted and time as 00:00:00.000. |
 |
|
|
naidu4u
Starting Member
23 Posts |
Posted - 2010-10-06 : 10:08:06
|
quote: Originally posted by madhivanan Where do you want to show formatted dates? If you use front end application, do formation thereMadhivananFailing to plan is Planning to fail
The problem is am using Cognos and there it is not letting me to convert the datatype...Thanks |
 |
|
|
pk_bohra
Master Smack Fu Yak Hacker
1182 Posts |
|
|
naidu4u
Starting Member
23 Posts |
Posted - 2010-10-06 : 10:46:39
|
quote: Originally posted by pk_bohra
quote: Originally posted by naidu4uI have tried this and this is giving me date how I wanted and time as 00:00:00.000.
Hi Naidu,AFAIK you cannot remove the timeportion from datetime datatype.The only way to remove them is to convert it to varchar and you cannot do that due to some limitation in cognos.I don't have any knowledge on cognos. I googled for you and found one link which says that you can convert varchar to date and vice-versa in cognos.http://publib.boulder.ibm.com/infocenter/cnow/v4r6m0/index.jsp?topic=/com.ibm.swg.im.cognos.sbi.4.6.0.doc/sbi_id13053NA0787.htmlRegards,Bohra
Thanks a lot Bohra, I will look into that and try to find something...appreciate your help....Thanks. |
 |
|
|
|
|
|
|
|