I want to show to user the notification date and time just like this forum does .... 1 minutes ago , 1 hours ago , 1 days ago and finally the exact date and time ....
this will give u differnece in date value of post_submit_time column and current date.... second, minute etc in this query are datepart keywords... and gives u difference in seconds or minutes etc.
upon this, u can build a logic to get most relevant datepart value... like if difference is more than 60 seconds then use minute value etc.
hope this helps...
Cheers!
KK
Please mark as Answer if post helps in resolving your issue
My Site
I have stored date and time in 1 column .... Dat is i have used datetime datatype. In sql 2008 there is seprate date and time datatype, so let me know how o store it.
1. I need to know how to store date and time using C# ... That is datetime.now.tostring(); Plz give example to store date and time in seprate column using C#.
2. Also i have a problem here, users are from different part of the world. So, how to show them their exact date and time... Plz suggest ...
Ashraf007
Member
382 Points
1728 Posts
Show notification of date and time just like 1 minutes ago , 1 hours ago , 1 days ago
Dec 07, 2011 05:53 AM|LINK
Hi ...
I want to show to user the notification date and time just like this forum does .... 1 minutes ago , 1 hours ago , 1 days ago and finally the exact date and time ....
Plz help me in this ....
kedarrkulkar...
All-Star
34401 Points
5529 Posts
Re: Show notification of date and time just like 1 minutes ago , 1 hours ago , 1 days ago
Dec 07, 2011 06:16 AM|LINK
you would want to show notification about some activity.... like this forum shows last post .. ago
you would have to capture date and time of that activity... for every post, capture post submit time...
when u want to display the time difference.... in database u can calculate difference in current time and last post time...
suppose u have simillar data for forum posts... u can use quesry like
select DTEEDIFF(second, post_submit_time, GETDATE()), DTEEDIFF(minute, post_submit_time, GETDATE()), DTEEDIFF(hour, post_submit_time, GETDATE()), DTEEDIFF(day, post_submit_time, GETDATE()) from tablename
this will give u differnece in date value of post_submit_time column and current date.... second, minute etc in this query are datepart keywords... and gives u difference in seconds or minutes etc.
upon this, u can build a logic to get most relevant datepart value... like if difference is more than 60 seconds then use minute value etc.
hope this helps...
KK
Please mark as Answer if post helps in resolving your issue
My Site
mudassarkhan
All-Star
78956 Points
13402 Posts
MVP
Re: Show notification of date and time just like 1 minutes ago , 1 hours ago , 1 days ago
Dec 07, 2011 06:31 AM|LINK
Refer these
http://stackoverflow.com/questions/11/how-do-i-calculate-relative-time
http://stackoverflow.com/questions/6074363/how-do-i-format-a-timespan-to-show-me-total-hours
Contact me
Ashraf007
Member
382 Points
1728 Posts
Re: Show notification of date and time just like 1 minutes ago , 1 hours ago , 1 days ago
Dec 07, 2011 07:30 AM|LINK
I have stored date and time in 1 column .... Dat is i have used datetime datatype. In sql 2008 there is seprate date and time datatype, so let me know how o store it.
1. I need to know how to store date and time using C# ... That is datetime.now.tostring(); Plz give example to store date and time in seprate column using C#.
2. Also i have a problem here, users are from different part of the world. So, how to show them their exact date and time... Plz suggest ...
mudassarkhan
All-Star
78956 Points
13402 Posts
MVP
Re: Show notification of date and time just like 1 minutes ago , 1 hours ago , 1 days ago
Dec 08, 2011 11:16 AM|LINK
the date displayed to all users will be same irrespective of their location because C# and SQL Server both use current date time of server.
Contact me
Ashraf007
Member
382 Points
1728 Posts
Re: Show notification of date and time just like 1 minutes ago , 1 hours ago , 1 days ago
Dec 10, 2011 01:17 PM|LINK
If i need to get user date and time mean what i have to do ?
dino Grievou...
Participant
844 Points
96 Posts
Re: Show notification of date and time just like 1 minutes ago , 1 hours ago , 1 days ago
Dec 12, 2011 04:25 AM|LINK
Hi Ashraf007
You can write a function like this:
static void StoreLastActionTime() { string Year,Month,Day,Hour,Minute; Year=DateTime.Now.Year.ToString(); Month=DateTime.Now.Month.ToString(); Day=DateTime.Now.Day.ToString(); Hour=DateTime.Now.Hour.ToString(); Minute=DateTime.Now.Minute.ToString(); //store them to DB }Then put them to you method like button1_click method.
This will get user location date. DateTime Class always be used to handle this problem.
For more information:
http://msdn.microsoft.com/query/dev10.query?appId=Dev10IDEF1&l=EN-US&k=k(SYSTEM.DATETIME);k(TargetFrameworkMoniker-%22.NETFRAMEWORK%2cVERSION%3dV4.0%22);k(DevLang-CSHARP)&rd=true
Dino