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
 General SQL Server Forums
 New to SQL Server Programming
 joining date

Author  Topic 

shan1430
Yak Posting Veteran

86 Posts

Posted - 2008-06-11 : 03:10:02
Hi,
I need to select date for my project.
I used the following

select datepart(yy,getdate())
select datepart(mm,getdate())
select datepart(dd,getdate()) -7

and i get

2008
6
4

How do I get the following result?
20080604
without any "." or "-"?
Thanks

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-11 : 03:34:44
Have a look at CONVERT() function in books online.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-06-11 : 03:38:46
SELECT CONVERT(CHAR(8), GETDATE() - 7, 112)



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

shan1430
Yak Posting Veteran

86 Posts

Posted - 2008-06-11 : 20:56:43
thanks for the reply, i used the following to get the date and also the week
select convert (varchar,getdate()-7,112)+ convert (varchar(10),datepart(wk,getdate())-1)
and i get the output as 2008060523, how do i put a white space between the date and week?
i need to get 20080605 23. thanks
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-06-12 : 00:17:20
select convert (varchar,getdate()-7,112)+ ' ' + convert (varchar(10),datepart(wk,getdate())-1)



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -