Solved

Date time syntax

Posted on 2011-03-02
7
323 Views
Last Modified: 2012-05-11
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
Comment
Question by:onebite2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 9

Expert Comment

by:rawinnlnx9
ID: 35022348
 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
 
LVL 13

Expert Comment

by:gamarrojgq
ID: 35022406
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
 
LVL 23

Accepted Solution

by:
wdosanjos earned 500 total points
ID: 35022456
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
Technology Partners: 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!

 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35022889
For rawinnlnx9 or wdosanjos' example, you would want to use TotalDays as opposed to Days.
0
 
LVL 23

Expert Comment

by:wdosanjos
ID: 35024085
@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
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35026027
@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
 
LVL 23

Expert Comment

by:wdosanjos
ID: 35027593
@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

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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Visual Studios 1 89
Passing data between Forms 3 26
VB.net SQL Concurrency violation tring save changes in DataGridView bound to data table 7 48
Need help with a query 3 39
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question