Link to home
Start Free TrialLog in
Avatar of onebite2
onebite2

asked on

Date time syntax

I am checking for a credit card related clause in vb.net code .Not sure how to check that,looking for syntax

'If  the credit card is there for 6 months more than the duedate in that table I need to remove the entry.'
I have a business object which holds all thefields for that table like (Card Expiration date,card create datetime)
Avatar of rawinnlnx9
rawinnlnx9
Flag of United States of America image

 TimeSpan span = System.DateTime.Now.Subtract (cardcreatedate);

if (span.Days > 180)
{
//Call stored proc to remove data.
// I am assuming that cardcreatedate is the datetime that the entry for the card was made in the table.
}

Open in new window

Avatar of gamarrojgq
gamarrojgq

Hi,


You can use AddMonths to validate it, I am going to assume that when you said "CREDIT CARD IS THER FOR 6 MORE THAN DUEDATE" you mean Credit Card Expiration Date, and that both fields are Date Type, so it will be something like this

If CreditCardExpirationDateField >= DueDate.AddMonths(6) Then
   'Remove the Entry
End if
ASKER CERTIFIED SOLUTION
Avatar of wdosanjos
wdosanjos
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kaufmed
For rawinnlnx9 or wdosanjos' example, you would want to use TotalDays as opposed to Days.
@kaufmed, I think TotalDays would make sense if the calculation involves date and time.  If both variables represent just dates, Days should have the same effect.
@wdosanjos

On second thought, I agree. It should have the same effect. I'm so used to working with the seconds/milliseconds members of TimeSpan that I just instinctively applied it here. After reviewing the documentation again, I see that, for the purposes of this question, Days and TotalDays would be equivalent.

The one "flaw" with this logic, though, is that there is an assumption of a flat 180 days equals six months. I think gamarrojgq's approach might be more appropriate here.
@kaufmed, I agree with your analysis.  @gamarrojgq approach is more flexible as it can address either requirements properly (180 days or 6 months).