Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Assign a System.DateTime variable to a System.DateTime[?]

Posted on 2013-01-25
Medium Priority
Last Modified: 2013-01-25
How do I assign a System.DateTime variable to a System.DateTime? variable?
Question by:allelopath
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
LVL 22

Expert Comment

ID: 38819330
just like you would any other datetime
LVL 22

Expert Comment

ID: 38819332
the other way though you would have to either cast to datetime or use the datetime?'s value property

Author Comment

ID: 38819337
I get this compile error:
Cannot convert source type System.Nullable<System.DateTime> to target type <System.DateTime>
LVL 22

Accepted Solution

p_davis earned 2000 total points
ID: 38819341
DateTime t1 = new DateTime();

DateTime? t2 = t1;

t1 = t2.Value
t1 = (DateTime)t2
LVL 45

Expert Comment

ID: 38819348
System.DateTime? means that it is either a System.DateTime OR a null.  
System.DateTime means it can ONLY be a System.DateTime.

In other words they are they same apart from one being able to have a value null.

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question