Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculate the difference between two dates

Status
Not open for further replies.

taree

Technical User
May 31, 2008
316
US
Hi all,

I am trying to calcuate the difference between two dates, between a date from the database and sysdate(todays date). I am using the below code and I am getting this kind of result. 28.0:00:00:00. How can I just display only 28 and remove the rest. can someone help me here or show me a better way to handle this. thanks


Dim DatDiff As DateTime = dsItem.Tables("ItemDetails").Rows(0).Item("Leet")
Dim DateDif As DateTime = System.DateTime.Now.ToShortDateString
lblDateD.Text = DatDiff.Subtract(DateDif).ToString
 
Not sure what the 28 is in your case, but just the relevant property from the returned TimeSpan object e.g.
Code:
...
...DatDiff.Subtract(DateDif).[b]Days[/b]

Mark,

[URL unfurl="true"]http://lessthandot.com[/url] - Experts, Information, Ideas & Knowledge
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Website Design
[URL unfurl="true"]http://aspnetlibrary.com[/url] - An online resource for professional ASP.NET developers
 
That did it for me. Thank you Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top