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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:45:38+00:00 2026-05-28T05:45:38+00:00

TimeSpan Earlybeforetime = new TimeSpan(); Earlybeforetime = earlybefore.Subtract(Convert.ToDateTime(outtime); Sometimes it returns a negative value.

  • 0
TimeSpan Earlybeforetime = new TimeSpan();
Earlybeforetime = earlybefore.Subtract(Convert.ToDateTime(outtime);

Sometimes it returns a negative value. How do I convert the value to be always positive?

  • 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-05-28T05:45:39+00:00Added an answer on May 28, 2026 at 5:45 am

    You could use Negate() to change the negative value to positive

    From MSDN

    If the date and time of the current instance is earlier than value,
    the method returns a TimeSpan object that represents a negative time
    span. That is, the value of all of its non-zero properties (such as
    Days or Ticks) is negative.

    So you could call the Negate method depending on which value is greater and obtain a positive Timespan

    Say we have startDate and endDate (endDate is greater than startDate), so when we do
    startDate.Subtract(endDate) we would get a negative TimeSpan. So based on this check you could convert the negative value. So if your outtime is ahead of earlybefore it would give you a negative TimeSpan

    EDIT

    Please check Duration() of the TimeSpan this should give you the absolute value always

    Earlybeforetime.Duration()

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

Sidebar

Related Questions

1) DateTime.Now returns a new DateTime instance. 2) DateTime.Subtract returns a new TimeSpan instance.
I want to compare datetime value and timespan value for the reason of non-negative
TimeSpan.Parse(23:00:00) returns 23 hours. TimeSpan.Parse(24:00:00) returns 24 days! I realize that I made a
TimeSpan time24 = new TimeSpan(24, 0, 0); TimeSpan time18 = new TimeSpan(18, 0, 0);
I am saving a TimeSpan (from .NET) value in my db as BIGINT in
I'm using a timespan function to work out the number of days, this value
How can I convert a timespan datatype to a long ?
Can you round a .NET TimeSpan object? I have a Timespan value of: 00:00:00.6193789
I created a TimeSpan this way TimeSpan ts = new Timespan(); // Do some
I have a value in TimeSpan , let's say: tsp1 = 2 hour 5

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.