Surya sasidhar
Surya sasidhar

Reputation: 30313

converting date in sql server 2005

In my application (asp.net) I am uploading the video and storing the video in database like videoname,videotitle,dateofuploded these are the fields. My problem is when I am displaying that video I want to display the date like '2 days ago' or ' one month ago' or 'one year ago'

How can I write the function for converting the date into that process.

Take example of youtube. On that site below the video display the date when it was uploaded.

Can I get that format of date if yes how can I write that.

Thank you

Upvotes: 2

Views: 106

Answers (2)

Quick Joe Smith
Quick Joe Smith

Reputation: 8222

The database is probably not the best side of the fence on which to do this. Because it's purely for visual purposes, it belongs in the UI layer of the application code.

Because the range of values (days, weeks, months, years) is finite, it doesn't have to be anything fancy, just a big if statement.

Upvotes: 2

Amirshk
Amirshk

Reputation: 8258

I don't know any built-in SQL functions that can do this, so i think you'll have to write some code for that.

See timespan-to-friendly-string-library-c for a C# example on how to do this.

Upvotes: 0

Related Questions