• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 333
  • 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)
0
onebite2
Asked:
onebite2
1 Solution
 
rawinnlnx9Commented:
 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

0
 
gamarrojgqCommented:
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
0
 
wdosanjosCommented:
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

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
käµfm³d 👽Commented:
For rawinnlnx9 or wdosanjos' example, you would want to use TotalDays as opposed to Days.
0
 
wdosanjosCommented:
@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.
0
 
käµfm³d 👽Commented:
@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.
0
 
wdosanjosCommented:
@kaufmed, I agree with your analysis.  @gamarrojgq approach is more flexible as it can address either requirements properly (180 days or 6 months).
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

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