Click here to Skip to main content
12,394,573 members (73,541 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#
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 2-Feb-12 1:33am
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
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 5

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.
  Permalink  
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.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

if (firstDate.Day == secondDate.Day && firstDate.Month == secondDate.Month) ...
  Permalink  
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.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

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.
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 6

Sorry for error,
Check this, it is fully functional:
SELECT * FROM TABLENAME
WHERE
((Day([ColumnName])=DAY(GETDATE())) and (MONTH([ColumnName]) = MONTH(GETDATE())))
  Permalink  
v2
Comments
SantoshRohinSantosh 6-Feb-12 0:33am
   
Thank you so much Yogesh It is working.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

DateTime sdate = Convert.ToDateTime(dtpFromDate.Text);
            DateTime edate = Convert.ToDateTime(dtpToDate.Text);
            TimeSpan ts = edate - sdate;
            int days = ts.Days;
  Permalink  
v2

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 4 Feb 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100