Passing Null Value for DateTime

datetime , null value , passing null value Toronto, Canada
  • 12 years ago
    hi, I have a textbox to input the date for Date of Joining. If I leave it blank and update my record, by default it inserts 1/1/1900 12:00:00 AM. But I want to send a null value here. How can I do that? Regards, Royal
  • 12 years ago
    Hi Can you please be more specific about the technologies you are using? I am using C# and I am not ale to figure out how you got the value '1/1/1900 12:00:00 AM' ... because it is neither the DateTime.MinValue, nor SqlDateTime.MinValue, nor the min value of the datetime data type used by the SQL server. So, my guess is that your app is using some data access layer that is transforming the empty string (from the textbox) into the '1/1/1900 12:00:00 AM' value ... or maybe a business logic layer ... anyway something custom. Therefore you should be able to spot it and fix it. Ciprian
  • 12 years ago
    Hi Ciprian, I am working on with C#. Yes I am working BL and DAL. But there is nothing in them which is changing the date to the said value. But now I am able to send a null value to the database table field, the "Issue Has Been Resolved". The issue was: the user will register on a form, the form has a field for date of birth, if the user leaves the field blank a null value should be posted in the database. And when the same has to be displayed : if there is null then the textbox should be blank else the date should be shown in a set format i.e. 'dd/mm/yyyy'. Thanks Regards, Royal
  • 12 years ago
    FYI, that datetime is what you'll get in SQL if you pass it an empty string rather than a null. As you can see if you run this in a query window: declare @t TABLE(dt datetime) insert into @t select '' select * from @t

Post a reply

Enter your message below

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“We better hurry up and start coding, there are going to be a lot of bugs to fix.”