Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 769635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:22:08+00:00 2026-05-14T18:22:08+00:00

I want to create a function that allows me to ban an account for

  • 0

I want to create a function that allows me to ban an account for 10days.
In the dbc, I have a field called “ban” and Boolean of 1=notban, 0=ban. I also have a field called “date_banned” which is just the timestamp of when the user got banned.

My question is how do I create a time frame of 10days from the date the user was banned?

ex: James was banned on “2010-05-03 20:43:48”. So how can I go about adding 10days to the timestamp? And after 10days, it would set the “ban” equal to 1(which is not banned).

EDIT: how can i show how many days the user has left of a ban? ex: 8 more days till unban

Can I…do NOW()-$date_banned? or how do I subtract the ban date from the current date?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T18:22:09+00:00Added an answer on May 14, 2026 at 6:22 pm

    To add 10 days to your date_banned field in MySQL, you can simply use the DATE_ADD() function. You could do the following check when the user tries to log-in, to see if the ban has expired:

    ... WHERE NOW() > DATE_ADD(date_banned, INTERVAL 10 DAY);
    

    Then you may want to toggle the ban field when the user tries to log in. Otherwise you can run a scheduled job every day, or at any other rate, that checks for expired bans and updates this field accordingly.

    However you do not actually need the ban field to check if a user is banned or not. In fact you may want to consider eliminating it. Actually, I would go further and suggest to use a banned_until instead of date_banned (or use them both). The banned_until field would make your queries simpler, and would allow you to predefine arbitrary ban durations at the time the ban is issued. In this case, when a user logs in, you can simply do the following check:

    ... WHERE NOW() > banned_until;
    

    UPDATE:

    To get the number of days remaining until the end of the ban, you can use the TIMESPANDIFF() function in MySQL:

    SELECT TIMESTAMPDIFF(DAY, NOW(), DATE_ADD(date_banned, INTERVAL 10 DAY)) ...
    

    Or if you were to use the banned_until field, it will be even shorter:

    SELECT TIMESTAMPDIFF(DAY, NOW(), banned_until) ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a function that performs a function passed by parameter on
I have a function that is effectively a replacement for print, and I want
I have a div that contains hundreds of lines. I want to create a
I am trying to create a function with a variant record-type parameter that allows
I want to create a function like a for loop where I will ideally
I want to create variables inside a function from a dictionary. Let's say I
I want to create a simple http proxy server that does some very basic
I have a Bourne Shell script that has several functions in it, and allows
Here's the scoop: I've created a test app that allows users to create ideas
I want create a drop shadow around the canvas component in flex. Technically speaking

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.