Click here to Skip to main content
15,912,329 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi experts..
i doing one project.. in that i can send emails for birthday wishes.. so how to compare currentdate and month and customer birthday date and month..

for ex:-

custmer birthday date is 1970-10-22 and current date is 2013-10-22.. today his birthday.. so how to compare both dates for send email


please help me.. thanks in advans







Thanks and regards..
Ch.Nagendra.
Posted
Updated 21-Oct-13 21:39pm
v2
Comments
Thanks7872 22-Oct-13 3:13am    
Not clear what you want to do.
Ankur\m/ 22-Oct-13 3:18am    
You must be getting customer birthdays from database. How your you storing it in your C# code?
NaniCh 22-Oct-13 3:37am    
suppose customer DOB is 1989-10-22. but current date is 2013-10-22.. today his birthday. how to compare both dates for send an email.

You can try something like

Fetch the DOBs from the DB and compare with current date

if (DateFromDb.Day == CurrentDate.Day && DateFromDb.Month == CurrentDate.Month)
{
//Your mail sending code
}

or

Compare the dates and the matching rows only from the DB query

SQL
SELECT * FROM TABLENAME WHERE
((Day([ColName])=DAY(GETDATE())) and (MONTH([ColName]) = MONTH(GETDATE())))


Hope this helps
 
Share this answer
 
Comments
NaniCh 22-Oct-13 7:40am    
Thanks for your help..
JoCodes 22-Oct-13 7:50am    
Nanich, You are welcome
Try with this code:-

C#
var yourDate = ...;
if(yourDate.Date == DateTime.Now.Date && yourDate.Month == DateTime.Now.Month)
{
    //Mail sending code
}
 
Share this answer
 
Comments
NaniCh 22-Oct-13 7:40am    
Thanks for your help..
Hi,
Try this.
C#
string test1 = DateTime.Now.ToString("dd/MM");
DateTime val = //your database value
string test2 = val.ToString("dd/MM");
if (test1 == test2)
{
    //send email
}
else
{
    
}

Hope it helps you.
Thanks.
 
Share this answer
 
v2
Comments
NaniCh 22-Oct-13 7:40am    
Thanks for your help..
Harshil_Raval 22-Oct-13 8:15am    
Oh!!! Any time. :)
Try:
SQL
DECLARE @StartDate DATETIME, @EndDate DATETIME

SET @StartDate = '2013-10-22'
SET @EndDate   = '2013-10-22'

SELECT FullName, DATEPART(MONTH, DateOfBirth) AS MONTH, DATEPART(DAY, DateOfBirth) AS DAY, CONVERT(VARCHAR(10), DateOfBirth, 111) AS DateOfBirth
    FROM Customers 
    WHERE   DATEADD(YEAR, DATEDIFF(YEAR,  DateOfBirth, @StartDate), DateOfBirth) BETWEEN @StartDate AND @EndDate
         OR DATEADD(YEAR, DATEDIFF(YEAR,  DateOfBirth, @EndDate), DateOfBirth) BETWEEN @StartDate AND @EndDate
    ORDER BY CASE WHEN DATEADD(YEAR, DATEDIFF(YEAR,  DateOfBirth, @StartDate), DateOfBirth) BETWEEN @StartDate AND @EndDate THEN 1 ELSE 2 END,
        DATEPART(MONTH, DateOfBirth), DATEPART(DAY, DateOfBirth)

Assuming your table name is "Customers" and the column name for DOB is "DateOfBirth"(I am assuming it to be of type DateTime). The same query can also be used to find DOB's within a date range.
 
Share this answer
 
v2
Comments
NaniCh 22-Oct-13 7:40am    
Thanks for your help..

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