Solved

Alternate to TimeSpan

Posted on 2009-05-12
5
443 Views
Last Modified: 2012-05-06
I have a date coming from database that I need to display to difference between now and that date. I know that is done with TimeSpan, but is that only way to use TimeSpan or any other way we can use..
lets say date is 5/30/2009 12:00:00 AM comes back from database and I want to see how many days left for my renewing my subscription.
how can I do that without TimeSpan if I can?
0
Comment
Question by:1jaws
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 18

Expert Comment

by:philipjonathan
ID: 24371371
You can get the number of days from the TimeSpan's Days property ...
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 250 total points
ID: 24371375
This still uses TimeSpan, but it gives you the number of days (would this be sufficient?):
DateTime d1 = "12/01/2009";  //Date from database
 
int days = d1.Subtract(DateTime.Now).Days;

Open in new window

0
 

Author Comment

by:1jaws
ID: 24371378
I have already done that I wonder any other way can be done or do I have to use TimeSpan for sure..
0
 
LVL 9

Assisted Solution

by:tetorvik
tetorvik earned 250 total points
ID: 24371493
Not saying this is advisable, but you can surely do this without TimeSpan.
            DateTime renewalDate = new DateTime(2010, 1, 1);
            int days = Convert.ToInt32((renewalDate.Ticks - DateTime.Now.Ticks) * 1.1574074074074074E-12);

Open in new window

0
 

Author Comment

by:1jaws
ID: 24371496
ok thanks for the advice, I think I will stick with TimeSpan :)
0

Featured Post

Is Your DevOps Pipeline Leaking?

Is your CI/CD pipeline a hodge-podge of randomly connected tools? You’ve likely got a tool to fix one problem & then a different tool to fix another, resulting in a cluster of tools with overlapping functionality. Learn how to optimize your pipeline with Gartner's recommendations

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question