473,785 Members | 2,480 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

null date?

why doesn't c# seem to support some kind of 'null date'

for instance:

i have an application where the user is not obliged to enter a date until
an event happens (e.g. a bug was fixed on xyz)

the calendar control in asp.net doesn't seem to have a selectedDate = null
property

is there any way around this?
--
#-)
Nov 15 '05 #1
6 10084
Hi,

The DateTime data type is a value type and not reference
type.

For more information about value types and reference
types, look at these url's

http://msdn.microsoft.com/library/default.asp?
url=/library/en-us/csref/html/vcrefvaluetypes .asp

http://msdn.microsoft.com/library/default.asp?
url=/library/en-us/csref/html/vcrefvaluetypes .asp

The bottom line is, the value type cannot hold null
values unlike reference types.

So the work arounds which i can think of is to,

1) Assign a date like 1/1/1900 which will be considered
as null.
2) Create a class which has a field of type date. This
can be done in a smart way, such that you use it like a
normal value type, i.e., you don't need to use 'new' to
create the instance of the class.
This can be acheived by using implicit operator.
Thus, you get the ease of use of value type and also for
types like date you can assign null value since the class
is a reference type.

Hope this helps!!

Regards,
Madhu

MVP | MCSD.NET
-----Original Message-----
why doesn't c# seem to support some kind of 'null date'

for instance:

i have an application where the user is not obliged to enter a date untilan event happens (e.g. a bug was fixed on xyz)

the calendar control in asp.net doesn't seem to have a selectedDate = nullproperty

is there any way around this?
--
#-)
.

Nov 15 '05 #2
Hiya,

This is a common challenge for developers with with the split
reference/value type system. Many developers go for a magic date which
"means" null but it is far from ideal. You may like to look at the
NullableTypes project being hosted at SourceForge. It provides wrapper
classes around the standard structs which are nullable. You will probably
want to see what impact these have on performance in your application - the
license terms seem to be OK.

----------------------------------------
- Mitch Denny
- mi*********@mon ash.net
- http://www.monash.net
- +61 (414) 610141
-

"evolve" <NOngnSPAMpeaSP AMrseNO_S__PAMh otmail.com> wrote in message
news:uX******** ********@TK2MSF TNGP09.phx.gbl. ..
why doesn't c# seem to support some kind of 'null date'

for instance:

i have an application where the user is not obliged to enter a date until
an event happens (e.g. a bug was fixed on xyz)

the calendar control in asp.net doesn't seem to have a selectedDate = null
property

is there any way around this?
--
#-)

Nov 15 '05 #3
You could use System.Data.Sql Types.SqlDate
"evolve" <NOngnSPAMpeaSP AMrseNO_S__PAMh otmail.com> wrote in message
news:uX******** ********@TK2MSF TNGP09.phx.gbl. ..
why doesn't c# seem to support some kind of 'null date'

for instance:

i have an application where the user is not obliged to enter a date until
an event happens (e.g. a bug was fixed on xyz)

the calendar control in asp.net doesn't seem to have a selectedDate = null
property

is there any way around this?
--
#-)

Nov 15 '05 #4
Use the static property DateTime.MinVal ue. (which is 01/01/0001 12:00AM)

This is considered to be a null date.

HTH
Brian w

"evolve" <NOngnSPAMpeaSP AMrseNO_S__PAMh otmail.com> wrote in message
news:uX******** ********@TK2MSF TNGP09.phx.gbl. ..
why doesn't c# seem to support some kind of 'null date'

for instance:

i have an application where the user is not obliged to enter a date until
an event happens (e.g. a bug was fixed on xyz)

the calendar control in asp.net doesn't seem to have a selectedDate = null
property

is there any way around this?
--
#-)

Nov 15 '05 #5
There is one caveat to using DateTime.MinVal ue... the actual date
(01/01/0001) is not supported by most database vendors. For example, I
believe that SQL Server throws an exception for dates less than 1/1/1900.
You can write code to get around this by translating the DateTime.MinVal ue
to a DbNull value before writing it to the database but this is a little
troublesome unless you have a good framework setup. For an enterprise
application, you wouldn't want to rely on individual programmers to
constantly be checking against the DateTime.MinVal ue every time a database
access occurs. As some of the other responses pointed out, a wrapper class
is a good way to avoid some of these issues.

Hopes this helps....

"Brian W" <brianw@gold_de ath_2_spam_rush .com> wrote in message
news:Oe******** *****@TK2MSFTNG P10.phx.gbl...
Use the static property DateTime.MinVal ue. (which is 01/01/0001 12:00AM)

This is considered to be a null date.

HTH
Brian w

"evolve" <NOngnSPAMpeaSP AMrseNO_S__PAMh otmail.com> wrote in message
news:uX******** ********@TK2MSF TNGP09.phx.gbl. ..
why doesn't c# seem to support some kind of 'null date'

for instance:

i have an application where the user is not obliged to enter a date until an event happens (e.g. a bug was fixed on xyz)

the calendar control in asp.net doesn't seem to have a selectedDate = null property

is there any way around this?
--
#-)


Nov 15 '05 #6
Ed
Which is great, but they don't serialize...
-----Original Message-----
You could use System.Data.Sql Types.SqlDate
"evolve" <NOngnSPAMpeaSP AMrseNO_S__PAMh otmail.com> wrote in messagenews:uX******* *********@TK2MS FTNGP09.phx.gbl ...
why doesn't c# seem to support some kind of 'null date'

for instance:

i have an application where the user is not obliged to enter a date until an event happens (e.g. a bug was fixed on xyz)

the calendar control in asp.net doesn't seem to have a selectedDate = null property

is there any way around this?
--
#-)

.

Nov 15 '05 #7

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

Similar topics

6
35366
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 db records are date type with null permissible. How should i handle the insertion of a null date record into the array? I just cant leave it empty right? K
8
10409
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 is not much help here either. Googling has given me a little help. This is my current understanding -- I would appreciate any comments or corrections... "" -- this means an empty string when applied to String data type, and also to Variant...
5
2154
by: tshad | last post by:
I have the following code: *************************************************************************** Dim CommandText as String = "INSERT INTO ftsolutions.dbo.position (client,dateposted) VALUES ( @client,@dateposted)" Dim objCmd as New SqlCommand(CommandText,objConn) with objCmd.Parameters .Add("@client",SqlDbType.Char,50).value = "the companies next test" .Add("@dateposted",SqlDbType.datetime).value = dateposted.text
6
12997
by: Dean Slindee | last post by:
I am looking for the "right" way to handle inserting and presenting null date values. Public Const c_NullDate As Date = #12:00:00 AM# If I set the value of a date variable in an SQL Server insert statement to c_NullDate, the insert statement works. When I re-read the row and display the inserted date value in a text box, the string "1/1/1900" is displayed. If one wanted the textbox to display an empty string, how should either the insert...
9
2324
by: John Sidney-Woollett | last post by:
Hi I'm building a web app where changes to customer orders are logged in the following table, and I worried about the time that it will take to locate records that need further processing/actioning. Here's the table: create table CUSTOMER.WCCustOrderStatusLog ( WCCustOrderID integer, WCOrderStatusID integer, -- date/time at which some process acknowledged the status
6
4318
by: recif20002002 | last post by:
Hello I am trying to update table1 and set a new value with a condition selecting only the results for the element with the specified ID and the first one with the Date field null. The query executes but it doesn t not update the informations. I ve tried using TOP 1 and spent hours on this query but i can t get it to work. UPDATE table1 SET table1.Name = newName
5
3172
by: Amogh | last post by:
Hi, My question is related to setting freed pointers to NULL. After freeing a pointer: 1) Should the freeing routine also be responsible for setting the pointer to null? 2) Or, should the client/user code be responsible for doing it? On what basis should a decision be made favouring either case ?
5
2639
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 create a record in the database for say a job, the invoicedOn date field will be left null within the data base, not being assigned untill its actually invoiced.
5
2710
by: M Skabialka | last post by:
I am creating my first Visual Studio project, an inventory database. I have created a form and used written directions to add data from a table to the form using table adapters, data sets, etc. I imported a table from an Access database which has some date fields. Many of these dates have never been filled in, so are nulls. If I look directly into the table data from Visual Studio it shows NULL. However, when I scroll from record to...
3
10015
by: cmartin1986 | last post by:
I have written a sql query and I need it to return 0 when it doesn't find any matches to my criteria. I have tried adding iif statements, tried sum, and just Count, all of these methods work fine to return the values when it finds matches, but i need it also to return a 0 when there are no matches. Here is what I got. SELECT "CAL Recieved" as Tags, .,sum(iif(.,1,0)) AS FROM GROUP BY . HAVING (((.)=(Date()-1))); UNION ALL SELECT...
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7499
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6740
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3646
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.