ASP.NET - find Date - Asked By msakt on 02-Jul-12 04:33 AM

in table dob have is varchar
        DOB
aaa    7/3
bbb   7/12
ccc     7/16
ddd   9/4
eee   1/6
fff      7/20

if i run query i want,who r  birthday current date to 15 days..dispaly
output
aaa
bbb
ccc   but fff is current month.but day is after 15 days so dont show  fff
Chintan Vaghela replied to msakt on 02-Jul-12 05:28 AM

Hi Frndz,

 

Functionality:  Get BOD current date to 15 days

 

 

To achieve this task,

 

 

First you need to make date

 

birthdate +'/'+ CAST( YEAR(GETDATE() ) AS VARCHAR)

 

After then CAST it to DateTime

 

CAST( birthdate +'/'+ CAST( YEAR(GETDATE() ) AS VARCHAR) as DATETIME)

 

After Added 14 to Current Date

 

DATEADD(Day,14,getdate())

 

Now get Data between two Date, Current Date and After 14 Days add Date

CONVERT(varchar(10),getdate(),102) and CONVERT(Varchar(10), DATEADD(Day,14,getdate()),102)

 

 

Check Below logic for more detail

 

 

Full Logic     :

 

 

select empname,birthdate from tblBirthDetail

WHERE

CONVERT(Varchar(10), CAST( birthdate +'/'+ CAST( YEAR(GETDATE() ) AS VARCHAR) as DATETIME),102)

BETWEEN CONVERT(varchar(10),getdate(),102) and CONVERT(Varchar(10), DATEADD(Day,14,getdate()),102)

 

 

 

Hope this helpful!

Thanks