Click here to Skip to main content
15,918,003 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
Now i create a website where user submit the some item. Now i want to when user see submit item then display which time ago submit item like codeproject site when we submit any item then display when submit. how to implement.
Posted

When you store the user input in the first place, store the current date and time in an SQL Date field.
When you display it, retrieve the information.

Can't be more specific, don't know how your site works...



"but how to display posted yesterday."

Use a TimeSpan: subtract the date posted from the current date (DateTime.Now) and check the Days property. If it is zero, the "posted Today". If it is one, then "posted Yesterday". Simple to work out "last week", "last month" and so on if you need it.
 
Share this answer
 
v2
Comments
Rakesh From Patna 1-Aug-11 9:07am    
but how to display posted yesterday.
OriginalGriff 1-Aug-11 9:20am    
Answer updated
Take one field into your table as PostedDate or any Name <br />
and set its Default value getDate()<br />
it will automatically add exact date and time of you stored Data <br />
then at the time of retrieving just calculate that according to your Requirement.
 
Share this answer
 
Comments
OriginalGriff 1-Aug-11 9:22am    
My only criticism on that is that it potentially uses a different date/time: it uses the database Server date and time, not the Web server - if you do any math, then you have to use the same date/time for everything.
Make a table and take a column as postedDate and set its data type as
Datetime and set default value as getdate().

now run this query as:

SQL
select datediff(d,postedDate ,getdate()) as DayOlder from tablename
 
Share this answer
 
v2
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900