0
public DateTime? SubscriptionStartDate { get; set; }

I want the datetime in string format after it has mapped a value:

SubscriptionStartDate = sheet.AUDIT_SHEET_SUBSCRIPTION_START_DATE

But i cant convert it to a string. I get the exception in my topic. I think i need to convert it to a non-nullable datetime object using the ?? operator, but im not sure how, since i never used it.

4
  • 3
    Hang on - you're assigning to SubscriptionStartDate... that means converting to a datetime, not from a datetime. It's not clear what you're really trying to do at the moment... Commented Oct 25, 2011 at 10:31
  • Which is it? Converting to a string or converting from a string? Commented Oct 25, 2011 at 10:32
  • typo, my bad. from datetime? to string Commented Oct 25, 2011 at 10:38
  • 1
    Can you update the title to match the body of the question then. Commented Oct 25, 2011 at 10:46

3 Answers 3

2

you need to check it has a value, then you can get the tostring from it. e.g.:-

if(SubscriptionStartDate.HasValue)
{
    String myValue = SubscriptionStartDate.Value.ToString();
}
Sign up to request clarification or add additional context in comments.

Comments

2

It is easy to use + operator

public DateTime? SubscriptionStartDate { get; set; }

string result = "" + SubscriptionStartDate 

Comments

0

Not sure this is a nullable issue per say.

Try (making sure to check for null first):

SubscriptionStartDate.parse( sheet.AUDIT_SHEET_SUBSCRIPTION_START_DATE )

( assuming you are retrieving a string and trying to assign a DateTime.... )

2 Comments

Im not recieving a string, im recieving a DateTime? and i want to convert it to a string.
SOrry, didnt see my typo, should be the opposite in the topic

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.