if statment based on elapsed time ..

J

Jim in Arizona

I want to make buttons available or not available based on how much time
has elapsed.

An example:

If NOW() > 8 hours then btnOne.Visible = False

Thanks.

Jim
 
J

Jim in Arizona

Patrice said:
And the problem you have is ? You can use the Hour method to get the hour
for the date object.

Try :
http://msdn2.microsoft.com/en-us/library/system.datetime.hour(VS.80).aspx

If Now.Hour>8 etc... (I would use Now.Hour>=9 for clarity)

Note also that this is server side code i.e. it won't if someone from
another time zone can connect (in this case you'll need likely to do this
client side using JavaScript).

I also found this resource:

http://blogs.msdn.com/vbfaq/

I'm actually making a communication log that employees in one location
on our domain will be using to pass down notes from one shift to the
next. I wanted to make sure that after they post that they will only be
able to modify their post for a few hours time then after that elapsed
time, the 'modify' and 'delete' buttons no longer show up.

I'll see if I can make your idea, along with what I found, work for this
project. If I can't, I'll be back.

Thanks.
 
P

Patrice

I would then subtract the creation date for this record from the current
date/time from to get the elapsed timespan since the creation.

Do you record the creation date/time for these notes ? (I suppose you want
recent notes to be updatable while older notes will be locked). You need to
record the creation date/time for these notes to get the elapsed time. You
can't IMO use the current date alone as you have to compare it ???

Sorry if obvious but I'm not sure to see what is the exact point on which
you have a problem (syntax, logic etc ?)...
 
R

Rad [Visual C# MVP]

I also found this resource:

http://blogs.msdn.com/vbfaq/

I'm actually making a communication log that employees in one location
on our domain will be using to pass down notes from one shift to the
next. I wanted to make sure that after they post that they will only be
able to modify their post for a few hours time then after that elapsed
time, the 'modify' and 'delete' buttons no longer show up.

I'll see if I can make your idea, along with what I found, work for this
project. If I can't, I'll be back.

Thanks.

One way would be to add some code in the page load to check the time
interval between the post datetime and the current date. If it is greater
than the threshold, you could then hide the buttons.

To make the code run periodically you could add a http header to refresh
the page every minute or so
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top