Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6067537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:37:07+00:00 2026-05-23T09:37:07+00:00

I want the date and time to be displayed as something like this on

  • 0

I want the date and time to be displayed as something like this on my page :-

 1 minute ago
25 minutes ago
45 minutes ago
4 hours ago
3 weeks ago

my stored procedure returns the date in the following format:-

2011-02-08 13:14:44.513

Can I format it the way I want it to be displayed in the SP only or do i have to do coding in the code behind of my aspx page?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T09:37:07+00:00Added an answer on May 23, 2026 at 9:37 am

    As far as I know there is no built in function to do this, however a case statement and some math can return what you want.

    I agree that it should be done behind the application rather than at the database level but that being said. Here is some code I threw together as an example, you should be able to modify it for your needs.

        DECLARE @SecDifference INTEGER
    
        DECLARE @OutPut nvarchar(25)
    
        DECLARE @CheckDate DATETIME
    
        SET @CheckDate = '2011-03-06 06:01:58.187'
    
    
        SET @SecDifference = (SELECT DATEDIFF(ss, @CheckDate ,GETDATE()))
    
        SET @OutPut = (CASE WHEN @SecDifference < 61 THEN CONVERT(VARCHAR(10), @SecDifference/60) + ' minute ago' 
                    WHEN @SecDifference > 60 AND @SecDIfference <= 3600 THEN CONVERT(VARCHAR(10), @SecDifference/60) + ' minutes ago' 
                    WHEN @SecDifference > 3600 AND @SecDifference <= 86400 THEN  CONVERT(VARCHAR(10), @SecDifference/3600) + ' hours ago' 
                    WHEN @SecDifference > 86400 AND @SecDifference <= 604800 THEN CONVERT(VARCHAR(10), @SecDifference/86400) + ' Day(s) ago' 
                    WHEN @SecDifference > 604800 AND @SecDifference <= 2419200 THEN CONVERT(VARCHAR(10), @SecDifference/604800) + ' Week(s) ago' 
                    WHEN @SecDifference > 2419200 AND @SecDifference < 29030400 THEN CONVERT(VARCHAR(10), @SecDifference/2419200) + ' Month(s) ago' 
                    ELSE 'NOT' END)
    
        SELECT @OutPut
        --RETURN @OutPut
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want the date&time to be in this format. For example 2012/3/21 23:47:01 2011/11/23
I want to do something like this.. I have a update form in PHP,
I want to display a date/time submitted value much the same way as Stack
I want to display the username/last connection date/time and some other info on all
I want to display the time and date of updated row from MySQL to
I want to provide an opportunity to change the date and time format in
I want to make a time or date listener which for example invoke an
i want to insert date & time to DateTimePicker. for example: date: 03/08/2009 time:
Background: I want to show the time and date uptill only 1 week. After
I want to store the current date & time which can be get by

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.