0

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

Edited by gahhon

3
Contributors
4
Replies
16
Views
4 Years
Discussion Span
Last Post by gahhon
0

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)

0
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")
0

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.