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..!!
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).
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With