Click here to Skip to main content
15,905,915 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi there,

i have table with field srno and date.

srno            date
1              10/3/2014
2              15/3/2014
3              20/3/2014
4              22/3/2014
5              25/3/2014 
6              26/3/2014


i want nearest upcoming date from today in gridview. if today is 22/3/2014 then result should be 25/3/2014.

so what will be the select query? answer in gridview c#.

srno            date
5              25/3/2014
Posted
Updated 21-Mar-14 16:59pm
v2
Comments
What have you tried?

1 solution

You can use the following query:


select * from test
where DateDiff(dd, GETDATE(), MyDateColumn) = (
select TOP 1 Min(DateDiff(dd, GETDATE(), MyDateColumn)) from Test WHERE MyDateColumn > GETDATE()
)


The subquery will get the difference in number of days for the nearest upcoming date. Then the outer query will select the records with that minimum difference.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900