• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 340
  • Last Modified:

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)
1 Solution
 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


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
Try this:

Dim ccIsThereDate As DateTime = #7/1/2010#
Dim dueDate As DateTime = #1/1/2011#

Console.WriteLine("Days {0}", (dueDate - ccIsThereDate).Days)

If (dueDate - ccIsThereDate).Days > 180 Then
   Console.WriteLine("The credit card is there for 6 months more than the duedate.")
End If

Open in new window

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

käµfm³d 👽Commented:
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.
käµfm³d 👽Commented:

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).
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now