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

  • SEARCH
  • Home
  • 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 8006729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:36:40+00:00 2026-06-04T17:36:40+00:00

I have a Datetime object which I take from an XML file (closingDate). I

  • 0

I have a Datetime object which I take from an XML file (closingDate).

I want to dynamically display all closingDates to the user. However, not all objects in the XML file necessarily contain a dateobject.

How can I do this (pseudocode):

DateTime closingDate = DateTime.Parse(xmlFile.selectSingleNode("Closing_Date")).toString();

and then later, I am writing out an HTML file with:

    String fileListHTML += "<li><a href='#'>The file name gets put here</a> (Closed:
"+closingDate+")</li>";

Now, as long as there is a datetime, there is no issue. However, if there is no datetime object (ie: null), I get an error.

Can I somehow do an if statement to say (again, pseudo):

if (closingDate =="")
{
   closingDate = "To be determined";
}

I am, of course, getting an error about casting a datetime to string.
Is there a way to do this?

  • 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-04T17:36:41+00:00Added an answer on June 4, 2026 at 5:36 pm

    I’m not a fan of turning DateTimes to strings until it is necessary.

    You could use a nullable DateTime. Use null to denote it’s not set or parsable. Alternatively scratch the nullable approach and use a sentinel such as DateTime.MinValue instead.

    This is untested but should get the point across:

    DateTime? closingDate;
    
    if (!string.IsNullOrEmpty(myClosingDateString))
    {
        closingDate = DateTime.Parse(myClosingDateString);
    }
    
    // do whatever else you need
    
    // when it comes time to appending ...
    
    if (!closingDate.HasValue) // or check if it's `DateTime.MinValue`
    {
        fileListHtml += "No closing date";
    }
    else
    {
        fileListHtml += closingDate.Value.ToString();
    }
    

    I’d caution you to be careful about converting DateTime to strings without considerations to time zones and internationalization (for example, DateTime.Parse() can interpret dates very differently depending on regional settings and/or the culture you pass in).

    For simplicity, if you can control the format of the string, I’d suggest using UTC and the ISO 8601 format.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a datetime object, for which I want to create a date string
I have web service in PHP which gets dateTime object (from asp) . I
Hi all i want a datetime object. In which I want to set time
I have a DateTime object I want to compare against an sql datetime field
I have this object: class a { public string Application; public DateTime From, To;
I have a DateTime object which I'm currently formating via $mytime->format(D d.m.Y) Which gives
I have a DateTime object which may or may not already contain some date/time
I have 2 DateTime objects, which I save to a file after using the
i have 5 datafunctions which all return the same type of object ( List<source>
I have this DateTime object (update) which is set to DateTime.now, when i update

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.