Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How I can convert Date to String formate.? [duplicate]

Tags:

c#

Possible Duplicate:
How do I calculate relative time?

I want to convert Date Value to string formate just like YouTube Videos Uploaded Time or Date for Eg. 2 Years Ago or 1 month ago or 8 houre ago like this just assume I have simple Date as an Output.

Thank you..!!

like image 649
Jitendra Jadav Avatar asked Jan 02 '12 13:01

Jitendra Jadav


People also ask

How do I change date to text without losing format?

Copy the dates that are in the cells that you want to convert. Copy the text and paste it into Notepad. Return to Excel and pick the cells into which you wish to paste the dates. Go to Home –> Number and pick the Text format with the cells chosen (from the drop down).

How do I convert a date to a string in Excel?

If you need to convert dates to text (i.e. date to string conversion) , you can use the TEXT function. The TEXT function can use patterns like "dd/mm/yyyy", "yyyy-mm-dd", etc. to convert a valid date to a text value.


1 Answers

DateTime now = DateTime.Now;

DateTime older = //orignal date time;

TimeSpan difference = now.Subtract(older);

Once you get the time span you can calculate years, month, days etc using properties time span class exposes

like image 56
Haris Hasan Avatar answered Oct 12 '22 09:10

Haris Hasan