Solved

Alternate to TimeSpan

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

856 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