Reputation: 365
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
}
Upvotes: 1
Views: 182
Reputation: 564451
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
}
Upvotes: 1