Click here to Skip to main content
15,868,141 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a question on the DateTime type.

I want to fetch the data from database whose bday's are on current date so i need to compare my current date with existing date and month.
plz help thanks.
Posted
Updated 2-Feb-12 15:15pm
v5
Comments
Rajesh Anuhya 2-Feb-12 21:15pm    
Edited: "Treat my content as plain text, not as HTML" disabled
--RA

Hello,
1. Try this Query if using SQL SERVER as Database,where TABLENAME is your table's name and ColumnName is your DateTime Column Name.

SELECT * FROM TABLENAME WHERE (Day(ColumnName)=DAY(GETDATE()) && MONTH(ColumnName) = MONTH(GETDATE()))

2. Try this Query if using MS ACCESS as Database,where TABLENAME is your table's name and ColumnName is your DateTime Column Name.

SELECT * FROM TABLENAME WHERE (Format(ColumnName, "d")=Format(Date(), "d") && Format(ColumnName, "m")=Format(Date(), "m"))

You will get results only of current date and month,than you process them as you want.
 
Share this answer
 
v2
Comments
Rajesh Anuhya 2-Feb-12 21:16pm    
Edited: Code Tags added
--RA
SantoshRohinSantosh 2-Feb-12 23:44pm    
Thanks yogesh but this is not working ,I am using SQL server so can you suggest me any other idea?Please.
C#
if (firstDate.Day == secondDate.Day && firstDate.Month == secondDate.Month) ...
 
Share this answer
 
v2
Comments
SantoshRohinSantosh 2-Feb-12 7:41am    
How to gate date and month only?
Chris Maunder 2-Feb-12 7:54am    
Please read the docs for the DateTime structure: http://msdn.microsoft.com/en-us/library/system.datetime.aspx. DateTime.Day, DateTime.Month are what you're after.
Yes you can do like this

DateTime dateGregorian = new DateTime(2009, 1, 13);
DateTime dateGregorian2 = new DateTime(2009,3, 14);
if(dateGregorian.Day==dateGregorian2.Day && dateGregorian.Month==dateGregorian2.Month)
{
 Your code ----
}



Thanks
SP
 
Share this answer
 
Query your database table (using SQL or Linq etc.,) to select row(s) where bday equals current date.

Then in your C# code loop through each row in the returned table to do whatever processing you need on the row.
 
Share this answer
 
Sorry for error,
Check this, it is fully functional:
C#
SELECT * FROM TABLENAME
WHERE
((Day([ColumnName])=DAY(GETDATE())) and (MONTH([ColumnName]) = MONTH(GETDATE())))
 
Share this answer
 
v2
Comments
SantoshRohinSantosh 6-Feb-12 0:33am    
Thank you so much Yogesh It is working.
DateTime sdate = Convert.ToDateTime(dtpFromDate.Text);
            DateTime edate = Convert.ToDateTime(dtpToDate.Text);
            TimeSpan ts = edate - sdate;
            int days = ts.Days;
 
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