1

What I want to do is block a user from doing something for 24 hours after they have reached a limit. I have coded the limit part, I just need to know how to block it if it hasn't been 24 hours.

Here is an example on how I want to do it. Update the user's account using a query and set the timestamp (Unix) to that time. Then I don't know how I can get another timestamp of the time they try to do it and check if the new timestamp is 24 hours between the last?

I have medium experience with C# but timestamps is one section I know nothing about with c#. Ss there anyone here that can help or provide a good tutorial? Or an idea on how I can learn more about it. I'm looking for the best way to do this. If Unix timestamps aren't it then please let me know and provide me with a better way if you can.

//Example
if (!CODE_HERE_FOR_NOT_24_HOURS)
{
    MessageBox.Show("You have reached your limit for today. Try again tomorow");
    return; 
}
else
{
    //Code here
}
2
  • I have updated the question. It has to be updated in a database due to my application restarting multiple times a day and i wouldn't be able to save it, Please tell me if im wrong with this. Commented Aug 8, 2014 at 17:50
  • 1
    @AshSmith You should be able to save a DateTime in the DB without issue. Commented Aug 8, 2014 at 17:50

1 Answer 1

1

In C#, you'd typically use DateTime.UtcNow, and use a DateTime, not a unix timestamp.

You can always check to see if its been less than 24 hours via:

if (timeStamp > DateTime.UtcNow.AddDays(-1))
{
   // It's been less than 24 hours
}
Sign up to request clarification or add additional context in comments.

4 Comments

Does this still apply to my update on my question? I have explained that it has to be updated in the database due to emulator reloading multiple times a day.
Would the timeStamp variable be the DateTime.Now that i save?
It would apply, but you would also need the additional step of saving timeStamp to the database, and loading it from the database when the app starts.
@AshSmith Yes - The DB should be able to store a DateTime without issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.