Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi! I want to show Upcoming Birthday with name, location from my MSSQL table empmaster.
My SQL code is
SQL
SELECT TOP 10 DOB, name, username
FROM empmaster
WHERE DATEPART(mm,DOB) = DATEPART(mm,GETDATE())
AND DATEPART(day,DOB) >= DATEPART(day,getdate())
OR DATEPART(mm,DOB) = DATEPART(mm,getdate())
ORDER BY DatePart(mm,DOB),DatePart(day,DOB)


My Asp.Net Code is:
ASP.NET
<div class="aspgrid">
                           <asp:GridView ID="Birthday_grid" runat="server" RowStyle Wrap="false" 
                            DataSourceID="SqlDataSource3" GridLines="Horizontal" >
                            <AlternatingRowStyle Wrap="False" />
                            <RowStyle Wrap="False"></RowStyle>
                            </asp:GridView>
                        <asp:SqlDataSource ID="SqlDataSource3" runat="server"
                        ConnectionString="<%$ ConnectionStrings:SQLDbConnection %>"
                        SelectCommand="SELECT TOP 10 DOB, name, username, department, location FROM empmaster WHERE DATEPART(mm,DOB) = DATEPART(mm,GETDATE()) AND DATEPART(day,DOB) >= DATEPART(day,getdate()) OR DATEPART(mm,DOB) = DATEPART(mm,getdate()) ORDER BY DatePart(mm,DOB),DatePart(day,DOB)"/>
                        </div>


Can Any Body help me to show upcoming Birthday of the month.
Posted

Try this

SQL
SELECT TOP 10 DOB, name, username
FROM empmaster
WHERE CONVERT(VARCHAR,DOB,101) > = CONVERT(VARCHAR,GETDATE(),101)
ORDER BY DOB


Hope this will help you.
 
Share this answer
 
try this.. :)

USE convert() function of sql like this...

SQL
select TOP 10 convert(varchar,DOB,106)AS DOB, name, username FROM empmaster where datepart(MM,DOB)=DATEPART(MM,GETDATE()) and datepart(dd,DOB) > datepart(dd,GETDATE()) order by DOB desc


it returns current month birsthday's but upcoming birthdays's only.. :)

for more conversion

Convert Datetime to string in many formats[^]
 
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