Date comparison in asp.net and C#

Posted: July 1, 2009 in ASP.net C#
Tags: , ,

public int IsGreaterApplyingDate(DateTime caldate, string student_id)
{

string ConvertedDate = GetDateToCompare(caldate);

string sSQL = “SELECT * FROM student_m where convert(nvarchar(10),date,112) >= ‘” + ConvertedDate + “‘ and id = ‘” + student_id + “‘”;

dt.Clear();
cmd.CommandText = sSQL;
da.SelectCommand = cmd;
da.Fill(dt);

if (dt.Rows.Count > 0)
return 0;
else
return 1;
}

public string GetDateToCompare(DateTime date)
{
string tDay = date.Day.ToString();
string tMonth = date.Month.ToString();
string tYear = date.Year.ToString();

if (tDay.Length == 1)
{
tDay = “0” + tDay;
}
if (tMonth.Length == 1)
{
tMonth = “0” + tMonth;
}

string CalModDate = tYear + tMonth + tDay;
return CalModDate;
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s