If the years are the same, compare the months, if the years are not the same, your year must be smaller than now:
var yourDate = ...;
if((yourDate.Year == DateTime.Now.Year && yourDate.Month < DateTime.Now.Month)
|| yourDate.Year < DateTime.Now.Year)
{
// yourDate is smaller than todays month.
}
UPDATE:
To check if yourDate
is in a certain time range, use this:
var yourDate = ...;
var lowerBoundYear = 2011;
var lowerBoundMonth = 1;
var upperBoundYear = 2012;
var upperBoundMonth = 4;
if(((yourDate.Year == lowerBoundYear && yourDate.Month >= lowerBoundMonth) ||
yourDate.Year > lowerBoundYear
) &&
((yourDate.Year == upperBoundYear && yourDate.Month <= upperBoundMonth) ||
yourDate.Year < lowerBoundYear
))
{
// yourDate is in the time range 01/01/2011 - 30/04/2012
// if you want yourDate to be in the range 01/02/2011 - 30/04/2012, i.e.
// exclusive lower bound, change the >= to >.
// if you want yourDate to be in the range 01/01/2011 - 31/03/2012, i.e.
// exclusive upper bound, change the <= to <.
}
Parse
always work for you ? parse it once and then play around with the values from the parsed instance, would be simpler – Tantalous