John
John

Reputation: 3945

take value of month from dateTime and convert to int?

So atm, Each workStation has a list of invoices for them, some workStations will have many invoices and some will have none. Each list of invoices is sorted ascending, and the most recent invoice is stored in 'lastInvoice'.

The below code checks the date on the last invoice compares it to this month -12. If the invoice date is < , it is stored in the chosenInvoicesForRetention list.

if (lastInvoice.Invoice_Date < DateTime.Now.AddMonths(-12))
       {
        chosenInvoicesForRetention.Add(workstation);
       }

This all works fine...however instead of DateTime.Now.AddMonths(-12) I would like to recplace this with a value which is stored in another table.

workstation.Number_of_Months

This returns the amount of months i.e between 1 and 12

Iv played about with it Operator can't be applied to 'int' or system.datetime.

Is it possible to pull the value of the month from the invoiceDate, and convert it to an int, then compare. as int etc....am I anywhere near correct? Please advise...thank ye

Upvotes: 0

Views: 129

Answers (3)

Rapha&#235;l Althaus
Rapha&#235;l Althaus

Reputation: 60493

not sure I understand (once again), but why not

if (lastInvoice.Invoice_Date < DateTime.Now.AddMonths(0 - workstation.Number_of_Months))
       {
        chosenInvoicesForRetention.Add(workstation);
       }

Upvotes: 1

Andres
Andres

Reputation: 2897

Is it possible to pull the value of the month from the invoiceDate, and convert it to an int, then compare.

Yes, you have to do this:

int month_number = lastInvoice.Invoice_Date.Month

Upvotes: 1

daryal
daryal

Reputation: 14929

I am not sure whether I understand the problem properly but;

if (lastInvoice.Invoice_Date < DateTime.Now.AddMonths(-1*workstation.Number_of_Months))

Upvotes: 1

Related Questions