Solved

Date time syntax

Posted on 2011-03-02
7
315 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
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 74

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 74

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now