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
 convert datetime.

Author  Topic 

mrjack
Yak Posting Veteran

50 Posts

Posted - 2006-07-11 : 04:49:34
Hi all..its kinda hard for me hw to figure out this, hopefully any of u guys can help me out with this super simple problem..

here is my query..
select convert(char(50),dateadd(day,-7,getdate()),105)
its because i want it to look last week data. BUT i get the format like this '03-07-2006'

what i want is it to be like this '20060703' how do i do that?

Thanks,
Jack

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2006-07-11 : 04:56:19
quote:
Originally posted by mrjack

what i want is it to be like this '20060703' how do i do that?




Jack, try this....

select convert(char(50),dateadd(day,-7,getdate()),112)


Harsh Athalye
India.
"Nothing is Impossible"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-07-11 : 04:57:25
No need for conversion and Formation. Try this

Select columns from yourTable
where Datecol>=DateAdd(day, DateDiff(day,0,Getdate()),-7)

Madhivanan

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

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-07-11 : 09:21:01
Are you storing date in string (char/varchar) data type or datetime data type ?


KH

Go to Top of Page
   

- Advertisement -