Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Time variation

Author  Topic 

shajimanjeri
Posting Yak Master

179 Posts

Posted - 2007-03-12 : 08:35:55
Hi

I have a website where members can add new messages to the site. But now I put somoe restrictions that for each member can add messages only the specified time intervals.
For eg:- for one member, I put the time interval is from 1 to 10 (its in hour format and datatype is varchar).Means this member can add messages in between the
time 1 AM and 10 AM. Now how to check whether current time is in between 1 and 10.

Pls help me!!

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-03-12 : 08:37:14
hour(getdate()) between 1 and 10


KH

Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-03-12 : 08:39:14
quote:
Originally posted by khtan

datepart(hour, getdate()) between 1 and 10


KH





Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

shajimanjeri
Posting Yak Master

179 Posts

Posted - 2007-03-12 : 09:41:36

Thanx Harsh Athalye and KH, Its working fine.

Now I have one more query, Suppose if one member added one new message at Morning 10'clock on today, so in the table this new mesage and the current datetime will be stored. Suppose the datetime he added the firt message is 03/12/2007 10:00:11 AM.
Now again the same member can add the second message
after 2 hour (datatype is varchar) only.(Its a permission to this member)
So here suppose if the same member is adding the second message, how to know whether he added the first message before 2 hour or not?

So how to put this permission.

Please help me!
Forget my bad english


quote:
Originally posted by harsh_athalye

quote:
Originally posted by khtan

datepart(hour, getdate()) between 1 and 10


KH





Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"

Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-03-12 : 09:53:43
Find out the last time user added the message. something like:

Select @lastmsgdate = max(msgdate) from tbl where userid = 'someuser'


Now find out the difference between lastmsgdate and current datetime using DATEDIFF() to check whether two hours elapsed after last message added or not.

select @hrselapsed = datediff(hour, @lastmsgdate, getdate())

If @hrselapsed > 2
-- ok
else
-- problem


Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page
   

- Advertisement -