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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:50:32+00:00 2026-06-14T18:50:32+00:00

Iam reading from an excel file 2 columns: One column has value: 07/11/2012 2nd

  • 0

Iam reading from an excel file 2 columns:

One column has value:
07/11/2012

2nd column has value:
18:45

When I read the 2nd column, it shows actually a default date in front of it.
dr[3].ToString() “30/12/1899 6:45:00 PM” string

I want to join the first column with the second. but right now I have the normal input format exception

I tried to remove the date part from the second column with string manipulation

here is my code

 DateTime dateEvent = DateTime.Parse(dr[1].ToString());
        dateEvent.Add(TimeSpan.Parse(dr[3].ToString().Substring(dr[3].ToString().IndexOf(" ")+1)));

Udpate 1:

DateTime dateEvent = DateTime.ParseExact(string.Format("{0} {1}", dr[1].ToString(), dr[3].ToString().IndexOf(" ") + 1), "dd/MM/yyyy HH:mm", CultureInfo.InvariantCulture);
  • 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-14T18:50:34+00:00Added an answer on June 14, 2026 at 6:50 pm

    EDIT: Looking at it again, I strongly suspect you don’t need to do any parsing at all. I suspect you could use:

    DateTime date = ((DateTime) dr[1]).Date;
    TimeSpan time = ((DateTime) dr[3]).TimeOfDay;
    DateTime combined = date + time;
    

    You shouldn’t just blindly call ToString() on values, without understanding what the type is: often it’s exactly the right type, and you can save yourself a potentially-lossy string conversion.


    Assuming you have to parse (rather than getting Excel to convert to a DateTime for you) I suggest using DateTime.ParseExact for both parts:

    • For the first part, use a format of dd/MM/yyyy
    • For the second part, use a format of dd/MM/yyyy hh:mm tt

    I’d suggest using the invariant culture explicitly – assuming you really know that this format is completely fixed. (If you don’t, that’s a bigger problem.)

    Then join them together like this:

    DateTime combined = date.Date + time.TimeOfDay;
    

    Alternatively, you could use my Noda Time library, which has separate LocalDate and LocalTime concepts, which can be combined easily into a LocalDateTime…

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

Sidebar

Related Questions

I am reading a percentage value from an excel file, and I need this
I am working in Windows Application. I am reading a value from Excel and
I am reading data from a file that has, unfortunately, two types of character
Hi I am reading an excel file with oledb(The file has 100000 rows). I
I am reading a cell value from excel using named range in my case
I am reading excel sheet using openrowset function? My Excel sheet has numeric value
I am using xlsread in MATLAB to read in sheets from an excel file.
I am copying a value 8.03 from excel sheet and reading that value in
I am reading data from an Excel worksheet. Some of the data is percent
I have a large text file I am reading from and I need to

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.