DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Handeling Blank Dates

  1. #1
    Join Date
    Feb 2010
    Central WV, USA

    Handeling Blank Dates

    I have a file that contains a date field. Sometimes this date is blank and other times it's not. In my validation routine, I first check for null then for a valid date. If no date exists I simly write a null field to file. But I'm afraid later on if this field gets loaded into a timedatepicker or another control that requires a valid date, I'm gonna have problems. I know I clould handle it when it loads and not even sent it to the control, but I was wanting some feedback first.

    So whats the proper way to write a blank date?
    Last edited by rrjii2000; 07-06-2010 at 05:35 PM.

  2. #2
    Join Date
    Feb 2004
    Longueuil, Québec
    Hi rrjii... it has been a while.

    And once again, that is one of those clear questions that have real meaning and importance, so I am always glad to try to help you.

    There are different ways to handle this, depending on what you define as a "Null field". The meaning is quite clear in a database, and the framework has built-in features to help you deal with a database Null (the IsDBNull function, the Nullable type).

    But in a file, you are the one defining what is Null or not.

    The best that I now is never to use Nulls, either as empty values in a file (or as a Null value in a database either). Nulls were a handy way to save space when we had only 350Kb diskettes and 64Mb of memory (and even less, I have worked with computers that had only 2Kb of memory; anybody remembers the Timex Sinclair?). With the systems we have nowadays, although we still need to be careful about memory and disk use, this is less of a consideration. And Nulls are a pain in the "what you know" to deal with.

    What is the best way to deal with a pain?

    Not having it in the first place.

    Personnally, I almost never use nulls in anything I do. I would rather use a dummy value that I treat as a Null. Sure there are cases where this is not convenient and nulls are the only way to go, such as having a field that store photos of products in the inventory. A Null then beats a dummy photo for a product for which we have no photo available.

    But for most of the usual types of fields, it is easy to find dummy values, that can be easily identified as dummy. Here are a few examples:

    • #01-01-1800# or #01-01-3000# for dates

    • -1 for a number when negative values makes no sense, such as a Quantity Ordered field

    • "<Undefined>" for Strings

    When I write to the file or the database, I detect empty values and simply write those personal null values instead. After reading back the values, I check for those and treat them as if they were Nulls in my operations.

    If you are careful enough, you will detect 3000-01-01 before putting it in a DateTimePicker and do whathever you want.

    But if you forget to check for that value and send it in anyway, the DateTimePicker or other control won't choke. It will surely display a strange date, but the application won't drop dead on your user.

    So to be short, "What is the best way to write a blank date?". Don't. Replace it with a dummy.

    And this holds True for most types of values, not only for dates.
    Jacques Bourgeois

  3. #3
    Join Date
    Feb 2010
    Central WV, USA
    as always, thanks for your help.

Similar Threads

  1. Replies: 4
    Last Post: 02-20-2010, 04:17 AM
  2. Data access and dates (simple question?!)
    By Neil Martin in forum VB Classic
    Replies: 1
    Last Post: 08-15-2002, 05:09 PM
  3. Using Data Access & dates (simple question!)
    By Neil Martin in forum VB Classic
    Replies: 4
    Last Post: 08-15-2002, 11:16 AM
  4. Multiple dates for one database entry
    By Seg in forum ASP.NET
    Replies: 5
    Last Post: 12-19-2001, 12:50 AM
  5. How to compare dates to get desired results... ?
    By Jaikumar Sharma in forum VB Classic
    Replies: 2
    Last Post: 04-01-2000, 12:58 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center