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 2005 Forums
 Transact-SQL (2005)
 select specific dates from getdate

Author  Topic 

jamie
Aged Yak Warrior

542 Posts

Posted - 2008-01-30 : 07:39:52
hi,
how can I display '2008-01-19' using getdate() and date functions ?

also display '2007-11-20' from getdate() ?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-01-30 : 07:41:10
check out convert() or do the formatting in your front end application


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-01-30 : 07:43:20
Where do you want to show data?

Madhivanan

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

jamie
Aged Yak Warrior

542 Posts

Posted - 2008-01-30 : 07:43:45
hi, thanks,
but I just had a brain wave and worked it out like :

--SET @Date3 = '2007-11-19'
SET @Date3 = DATEADD(mm,-2,DATEADD(dd,18,DATEADD(mm, DATEDIFF(mm,0,getdate()), 0)))
--SET @Date1 = '2007-12-20'
SET @Date1 = DATEADD(mm,-1,DATEADD(dd,19,DATEADD(mm, DATEDIFF(mm,0,getdate()), 0)))
--SET @Date2 = '2008-01-19'
SET @Date2 = DATEADD(dd,18,DATEADD(mm, DATEDIFF(mm,0,getdate()), 0))

! cheers.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-01-30 : 07:48:14
quote:
Originally posted by jamie

hi, thanks,
but I just had a brain wave and worked it out like :

--SET @Date3 = '2007-11-19'
SET @Date3 = DATEADD(mm,-2,DATEADD(dd,18,DATEADD(mm, DATEDIFF(mm,0,getdate()), 0)))
--SET @Date1 = '2007-12-20'
SET @Date1 = DATEADD(mm,-1,DATEADD(dd,19,DATEADD(mm, DATEDIFF(mm,0,getdate()), 0)))
--SET @Date2 = '2008-01-19'
SET @Date2 = DATEADD(dd,18,DATEADD(mm, DATEDIFF(mm,0,getdate()), 0))

! cheers.



what are you trying to achieve here ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

mightypenny_ph
Yak Posting Veteran

54 Posts

Posted - 2008-01-30 : 08:12:27
select convert(varchar, getdate(), 102) - 2008.01.01

SlayerS_`BoxeR` + [ReD]NaDa
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-01-30 : 09:32:32
quote:
Originally posted by jamie

hi, thanks,
but I just had a brain wave and worked it out like :

--SET @Date3 = '2007-11-19'
SET @Date3 = DATEADD(mm,-2,DATEADD(dd,18,DATEADD(mm, DATEDIFF(mm,0,getdate()), 0)))
--SET @Date1 = '2007-12-20'
SET @Date1 = DATEADD(mm,-1,DATEADD(dd,19,DATEADD(mm, DATEDIFF(mm,0,getdate()), 0)))
--SET @Date2 = '2008-01-19'
SET @Date2 = DATEADD(dd,18,DATEADD(mm, DATEDIFF(mm,0,getdate()), 0))

! cheers.


Good. Setting Time part to 0 is the effecient way

Madhivanan

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

- Advertisement -