How do i compare the months from database where my database records are stored in date format (12/12/2013)
Ignoring the days.
For example

This Month 12/08/2013
Next Month 12/09/2013

if both are match, i will return my true else false?

        protected void renewCurrentBudget()
        {
            Boolean renew = true;
            DateTime nextMonth;

            SqlConnection conNew = new SqlConnection(ConfigurationManager.ConnectionStrings["connMSJ"].ConnectionString);
            SqlCommand cmdNew = new SqlCommand("UPDATE Member SET CurrentBudget=@current WHERE Username=@username", conNew);
            SqlCommand cmdToday = new SqlCommand("SELECT NextMonth FROM MonthlyBudget WHERE (Username=@username AND ThisMonth=@previousMonth)", conNew);
            cmdNew.Parameters.AddWithValue("@current", getMonthlyBudget());
            cmdNew.Parameters.AddWithValue("@username", Master.getUsername);
            cmdToday.Parameters.AddWithValue("@username", Master.getUsername);
            cmdToday.Parameters.AddWithValue("@previousMonth", DateTime.Now.AddMonths(-1).Month);
            conNew.Open();
            SqlDataReader dtrToday = cmdToday.ExecuteReader();
            while (dtrToday.Read())
            {
                renew = false;
            }
            dtrToday.Close();

            if (renew == true)
                cmdNew.ExecuteNonQuery();
            conNew.Close();
        }

by using the parameters to compare

I found the answer. This is the easiest way to do that.

d_now = date()
d = split(DateAdd("d",1,d_now),"/")
s = d(2) & "-" & d(0) & "-" & d(1)

Dim arrParts() As String
Dim theDate As Date

arrParts = Split(strOldFormat, ".")
theDate = DateTime.DateSerial(parts(2), parts(1), parts(0))

strNewFormat = Format(theDate, "mm.dd.yyyy")

Thanks everyone. Problem solved.

Solution

Create a new method that mostly used to comparing
Assignment those day, month and year to int variables seperately
then compare.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.