Solved

Alternate to TimeSpan

Posted on 2009-05-12
5
432 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
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 74

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This video discusses moving either the default database or any database to a new volume.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now