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
 To select future date

Author  Topic 

Sam86
Starting Member

5 Posts

Posted - 2008-07-31 : 07:52:15
Hi All,
My table contains DateTime Field
which Contains values
1.2008-07-10 17:10:43.670

2.2008-07-31 17:10:42.670
3.2008-07-12 17:31:42.670
4.2008-07-15 17:52:42.670
5.2008-08-03 17:45:42.670
6.2008-07-16 17:23:42.670
7.2008-08-04 17:35:42.670
8.2008-07-31 17:35:42.670
9.2008-07-01 17:25:42.670
10.2008-08-02 17:20:42.670



i need 2,5,7,8,10 columns as answers .How i need answers is ,the dates will be
future dates from today and including today date .

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-07-31 : 08:00:53
[code]select *
from mytable
where DateTime >= dateadd(day, datediff(day, 0, getdate()), 0)[/code]


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

Go to Top of Page

Sam86
Starting Member

5 Posts

Posted - 2008-07-31 : 08:21:41
Thank you its working correct.But if had date 7/31/2008 ,i need answer as Thursday, July 31 ,2008 as answer
Go to Top of Page

VGuyz
Posting Yak Master

121 Posts

Posted - 2008-07-31 : 08:34:13
Hi chk this

select * from table where datetimefield >getdate()
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-07-31 : 08:34:56
quote:
Originally posted by Sam86

Thank you its working correct.But if had date 7/31/2008 ,i need answer as Thursday, July 31 ,2008 as answer



That is just presentation of the date. Format it to the required format in your front end application


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

Go to Top of Page

VGuyz
Posting Yak Master

121 Posts

Posted - 2008-07-31 : 08:38:54
Hi chk this,

SELECT DATENAME(DW, GETDATE())+', '+ DATENAME(MM, GETDATE()) + RIGHT(CONVERT(VARCHAR(12), GETDATE(), 107), 9) AS [Weekday ,Month DD, YYYY]
Go to Top of Page

Sam86
Starting Member

5 Posts

Posted - 2008-07-31 : 08:41:13
For VGuyz

That too getting answer but not getting todaydate
Go to Top of Page

Sam86
Starting Member

5 Posts

Posted - 2008-07-31 : 08:45:25
i dont need for todaydate and i need for future dates and todaydate which was in database table
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-07-31 : 09:02:01
Sam, what is the issue ? The query i posted earlier gives you the required result ?

quote:
i need answer as Thursday, July 31 ,2008 as answer

Not sure what do you mean here but basically this is just a presentation issue. Do the required formatting at your front end application. If you had to do it in T-SQL then check out the Books Online on CONVERT().


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

Go to Top of Page

VGuyz
Posting Yak Master

121 Posts

Posted - 2008-07-31 : 09:14:29

quote:

Posted - 07/31/2008 : 08:41:13
For VGuyz

That too getting answer but not getting todaydate


Instead of getdate() put u'r column name in the query.
Go to Top of Page

Sam86
Starting Member

5 Posts

Posted - 2008-07-31 : 09:16:24
k.Thank you i got the answer
Go to Top of Page
   

- Advertisement -