Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 19th, 2007, 3:36 PM   #1
sackarias
Programmer
 
sackarias's Avatar
 
Join Date: Jan 2006
Posts: 58
Rep Power: 3 sackarias is on a distinguished road
Problems with Date objects

I'm writing a program that's interacting with a database that has two tables. The table relevant to my question is my customer table, which has a Date/Time field that expresses the current customers account expiration date.

I'm having trouble comparing a customer's expiration date to another date object to verify if their account expired.

This code checks if a Dvd is checked out, if it isn't, ask the user's account number. Next I check (where error keeps occuring) if the expiration date is prior to todays date, thus making it valid, but it doesn't work that way. In which ways can you go about comparing two dates? Maybe I missed a certain method pertaining to comparing dates, I saw a compareTo, nothing like an isLessThen or similar. Any help would be greatly appreciated, thanks a lot. Also, when I copied my code over it automatically put returns so it's sort of hard to read, sorry for that.

If dbSetAdapter.Tables("Dvds").Rows(index).Item("CheckedOutBy") = "XXXXXXX" Or 0 Then
            response = InputBox("Enter your account number", "Account Number")
            If findAccount(response, 0) <> -1 Then
                accountIndex = findAccount(response, 0) 'account found, put index in variable
                If cusSet.Tables("Customer").Rows(accountIndex).Item("ExpirationDate") < Date.Today Then  'ERROR HERE, How to compare if one date is "less then" another
                    MessageBox.Show("not expired")
                End If
            Else
                MessageBox.Show("Account number does not exist")
            End If
        Else
            MessageBox.Show("This DVD is checked out.")
        End If
sackarias is offline   Reply With Quote
Old Nov 19th, 2007, 3:58 PM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Re: Problems with Date objects

You can deal with dates in a number of different ways. If you think hard enough and work hard enough, you can even deal with them correctly.

My approach is to convert evey date that is to be subjected to manipulation to a form that represents a a numerical value expressing time elapsed since some benchmark time in the past.

You, too, can do this. It doesn't much matter whether you read the material pertaing to VB, or to PHP, or to C, or to a non-language entity such as an operating system. Read, understand, adapt, and write.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Jan 9th, 2008, 12:46 PM   #3
SydneyMcConnell
18 Year Old Programmer
 
Join Date: Jan 2008
Posts: 26
Rep Power: 0 SydneyMcConnell is on a distinguished road
Re: Problems with Date objects

Enclose cusSet.Tables("Customer").Rows(accountIndex).Item("ExpirationDate") in a CDate, and see if that solves the issue. In some cases, it may not implicitly convert an object in an equation when you're working with Data, and so it may just stay as an object.

It should be like:
If CDate(cusSet.Tables("Customer").Rows(accountIndex).Item("ExpirationDate")) < Date.Today Then

Try that, and see if it works. Could be overly simple, and perhaps you've tried it before, but it might work.
SydneyMcConnell is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding to a date variable? Emperor Visual Basic 1 May 11th, 2007 12:11 AM
having problems with programming the NIM wizardchik C++ 4 Feb 25th, 2007 9:49 PM
Date Routine tbohon Perl 2 Jan 15th, 2007 11:14 AM
OOP Theory - MI of Objects Darkhack Other Programming Languages 4 Feb 16th, 2006 7:34 AM
date question rjbrynteson ASP 3 Oct 19th, 2005 3:24 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:58 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC