473,396 Members | 1,853 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Handling Null Dates

Hello Everyone and thanks for your help in advance. I am developing an application that utilizes a separate class library for data access to a SQL Server database. One of the tables has several fields defined as DateTime. The data access layer exposes properties for each field in the table. In the instance of datetime fields, the class returns a property of date type. The problem occurs when one of the datetime fields is NULL, which results in a value of 12:00:00 AM being returned. I then tried the following code

If Not IsDBNull(myclass.mydate) the
myTextbox.Text = myClass.myDat
Els
mytextbox.Text = "
End I

However, it still returned the 12:00:00 AM. Is there any way around this problem other than returning a string value, that converting it is datetime functions are required? Any help would be greatly appreciated. Thanks.
Nov 22 '05 #1
3 2609
It sounds like your class is reading the value of the datetime field
and making it "12:00:00 AM". From then on, the value is not null, but
that time.

Option A: In your class, when reading the value of the datetime field
from the database, set the value to Null instead of midnight.

Option B: When reading the value of myClass.myDate, instead of
checking for DBNull, check for "12:00:00 AM". Of course, if a real
time of midnight were ever there, this would fail. I assume though
that your actual datetime would include dates, so this should work.
Just a bit kludgy.

On Sat, 28 Feb 2004 09:26:05 -0800, kmcnet
<an*******@discussions.microsoft.com> wrote:
Hello Everyone and thanks for your help in advance. I am developing an application that utilizes a separate class library for data access to a SQL Server database. One of the tables has several fields defined as DateTime. The data access layer exposes properties for each field in the table. In the instance of datetime fields, the class returns a property of date type. The problem occurs when one of the datetime fields is NULL, which results in a value of 12:00:00 AM being returned. I then tried the following code:

If Not IsDBNull(myclass.mydate) then
myTextbox.Text = myClass.myDate
Else
mytextbox.Text = ""
End If

However, it still returned the 12:00:00 AM. Is there any way around this problem other than returning a string value, that converting it is datetime functions are required? Any help would be greatly appreciated. Thanks.


Nov 22 '05 #2
Thanks Dan. That does work. However, I am not sure why it is being set to 12:00:00 am in the first place. The code I am using is as follows

To initialize the variabl

Private _HireDate As Dat

Then on the read from the database

If Not IsDBNull(myReader("HireDate")) The
_HireDate = Trim(myReader("HireDate")
End I

Finally, the property is set

'HireDat
ReadOnly Property HireDate() As Dat
Ge
Return _HireDat
End Ge
End Propert

So, I really can't figure out where the 12:00:00 am come from. Any insight?
Nov 22 '05 #3
On Sat, 28 Feb 2004 10:21:05 -0800, kmcnet <an*******@discussions.microsoft.com> wrote:

¤ Thanks Dan. That does work. However, I am not sure why it is being set to 12:00:00 am in the first place. The code I am using is as follows:
¤
¤ To initialize the variable
¤
¤ Private _HireDate As Date
¤
¤ Then on the read from the database:
¤
¤ If Not IsDBNull(myReader("HireDate")) Then
¤ _HireDate = Trim(myReader("HireDate"))
¤ End If
¤
¤ Finally, the property is set:
¤
¤ 'HireDate
¤ ReadOnly Property HireDate() As Date
¤ Get
¤ Return _HireDate
¤ End Get
¤ End Property
¤
¤ So, I really can't figure out where the 12:00:00 am come from. Any insight?

Because uninitialized dates have a default value of 1/1/0001 12:00:00 AM.
Paul ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)
Nov 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Kris M | last post by:
How do i handle a null value for a date variable type. I am retrieving date data from an access database and storing the records in an array for processing. The array field has a date type and the...
3
by: kmcnet | last post by:
Hello Everyone and thanks for your help in advance. I am developing an application that utilizes a separate class library for data access to a SQL Server database. One of the tables has several...
12
by: Christian Christmann | last post by:
Hi, assert and error handling can be used for similar purposes. When should one use assert instead of try/catch and in which cases the error handling is preferable? I've read somewhere that...
8
by: Lyn | last post by:
I am trying to get my head around the concept of default, special or empty values that appear in Access VBA, depending on data type. The Access Help is not much (help), and the manual that I have...
4
by: wapsiii | last post by:
I'm unsure how best to handle dates from my webforms to my database. Often I have a textbox and a datepicker on a webform. Upon postback dates are received in string format (like DD-MM-YYYY)....
2
by: Yog | last post by:
Is there a best way to handle various formats of dates for SQL server?. The data comes in various input files with different date formats. The ParseExact function looks like an "evil" and it...
34
by: Chad | last post by:
Given the following code that achieves no useful purpose: #include <string.h> #include <stdio.h> #include <string.h> int manip(char *str) { size_t len = strlen(str)-1; if(len >= 3) {
5
by: AAJ | last post by:
Hi Does anyone know of any good publically available set of standards for managing dates when dealing with a database server (in my case SQL Server 2000 and c# VS2005). At the moment, if I...
4
by: Jeff Goodman | last post by:
If there is a better newsgroup to post this in, please let me know. I am a relatively new VB.NET/SQL 2000 programmer. I am working with data imported into SQL2K from Access. Many of the dates...
2
by: Jim Carlock | last post by:
(1) Does PHP provide any way to handle dates prior to 1980? I know there's problems with Microsoft Windows NT and all Windows NT operating systems will allow a date prior to 1980 to be placed...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.