Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8304343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:49:18+00:00 2026-06-08T17:49:18+00:00

Can a DateTime value be NULL ? I have this code: From here I

  • 0

Can a DateTime value be NULL?

I have this code:

From here I inherit my variable

namespace Transakcija
{
     public class Line
     {
        public System.DateTime DateOfProduction { get; set; }
     }
}

Then for each loop:

foreach (var rw_det in dt_stavke.Rows)
{
    var list = new List<Transakcija.Line>();
    var l = new Transakcija.Line();

     //DateOfProduction
    if (rw_det["DPRO02"].ToString().Length <= 0)
    {
        l.DateOfProduction = default(DateTime);
    }
    else
    {
        l.DateOfProduction = new DateTime();
        prod_date = rw_det["DPRO02"].ToString();
        DateTime pro_date = DateTime.ParseExact(prod_date, "dd.MM.yyyy", CultureInfo.InvariantCulture);
        string p_date = pro_date.ToString("yyyy-MM-dd");
        l.DateOfProduction = DateTime.Parse(p_date);
    }
}

So the value l.DateOfProduction needs to be null. I have tried this:

DateTime? dt = null;
l.DateOfProduction = (DateTime)dt;

But I got error: nullable object must have a value

So is this possible or do I have to pass the minimum datetime value to the variable?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T17:49:21+00:00Added an answer on June 8, 2026 at 5:49 pm

    You can assigne a nullable DateTime by using the constructor:

    DateTime? dt = new Nullable<DateTime>(); 
    

    You can check if a nullable type is null by using the HasValue property:

    if(dt.HasValue)
    {
        // now you can safely use dt.Value as DateTime, 
        // otherwise accessing the Value property raises an InvalidOperationException
        DateTime otherDate = dt.Value;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I get DateTime value in C# from row, the current code is
I am using Datetime.Minvalue which return 1.1.0001. This value can not be stored to
I have a code first database. The tables causing me issues are public class
I want to convert 8 digit value to a DateTime object. How can I
I have a Linq2Sql query that looks like this: var data = from d
I have a table: CREATE TABLE [Lines] ( [Value] TEXT NOT NULL, [AddedOn] TIMESTAMP
I have a pipe delimited file with some NULL date fields. I load this
I have the following code: DateTime pickerDate = Convert.ToDateTime(pickerWakeupDate.SelectedDate); string enteredStr = pickerDate.ToShortDateString() +
I have data in my database that looks like this: Date (DateTime) Type (varchar)
How can I convert DateTime Thu Nov 30 19:00:00 EST 2006 to 11/30/2006

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.