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 7976467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:54:58+00:00 2026-06-04T08:54:58+00:00

I have a: DateTime?[] dates I need to convert to: Double?[] oaDates Any way

  • 0

I have a:

DateTime?[] dates

I need to convert to:

Double?[] oaDates

Any way to clean up this one liner? Or should I just resort to a function?

DateTime?[] dates = new DateTime?[]{DateTime.Now, DateTime.Now.AddDays(1), DateTime.Now.AddDays(2)}; //example array
Double?[] oaDates = dates.Select(t => (t==null)?((double?)null):(t??DateTime.MinValue).ToOADate()).ToArray();

I can’t call a method on t without checking that it’s null (hence the tertiary operator) and I have to coalesce it as well so that I can call OADate (hence the coalesce and filler DateTime.MinValue that will never be hit).

It gets the job done in one line, but it is looking a little perl-like.

Maybe an extension method? That way I can hide the ugliness and just do something along the lines of:

dates.ToNullableOADates();
  • 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-04T08:55:00+00:00Added an answer on June 4, 2026 at 8:55 am

    You can actually call extension methods on null references. So you could define an extension method to convert a single DateTime? to a double? like:

    public static class DateUtil
    {
        public static double? ConvertToDouble(this DateTime? date)
        {
            return date.HasValue ? date.Value.ToOADate() : (double?)null;
        }
    }
    

    Then call it like:

    double?[] oaDates = dates.Select(t => t.ConvertToDouble()).ToArray();
    

    However, you could equally call it using the method group syntax:

    double?[] oaDates1 = dates.Select(DateUtil.ConvertToDouble).ToArray();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this: var date = new DateTime(2009, 12, 5); ... ... and need
I have to compare three dates in linq query (datetime a < datetime b
I have an IEnumerable<DateTime> . I would like to pull out all dates that
I have the following: PMRCutoffDate.Value = ReportCalc.Cutoff_Date.ToString(MM/dd/yyyy); PMRDate.Value = DateTime.Now.ToString(MM/dd/yyyy); i want dates to
I have this table: ID(INT) DATE(DATETIME) Under the DATE column there are a lot
In mysql database i have this column called: Name: Date Type: datetime I have
I have birth dates stored as datetime in SQL Server 2008 like so: 2010-04-25
I need a universal way to store dates and datetimes in several databases (for
i have made a function which works just fine with 32-bit dates (acceptable with
I need to convert dates into Excel serial numbers for a data munging script

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.