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

  • SEARCH
  • Home
  • 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 6740971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:40:12+00:00 2026-05-26T11:40:12+00:00

In a web application I’m writing for an existing database I need to calculate

  • 0

In a web application I’m writing for an existing database I need to calculate the difference between now and a timestamp stored in the database (in a text field, it’s stupid, I know). Here’s my sqlalchemy Ban class and the relevant method.

class Ban(base):
    __tablename__= 'bans'

    id= Column('banID', Integer, primary_key=True)
    unban_timestamp= Column('UNBAN', Text)
    banned_steamid= Column('ID', Text, ForeignKey('rp_users.steamid'))
    banned_name= Column('NAME', Text)
    banner_steamid= Column('BANNER_STEAMID', Text, ForeignKey('rp_users.steamid'))
    banner_name= Column('BANNER', Text)
    reason= Column('REASON', Text)

    def unbanned_in(self, mode):
        if self.unban_timestamp == '0':
            return 'Never'
        else:
            now= datetime.datetime.utcnow()
            time= datetime.datetime.fromtimestamp(int(self.unban_timestamp))
            if now > time:
                return 'Expired'
            else:
                remaining= time - now
                if mode=='readable':
                    return remaining
                elif mode=='int':
                    return str(remaining.seconds).zfill(10)

I need both the integer and the pretty string representations because I’ll be presenting this in a html table and javascript needs a simple way to sort it. The problem I’m facing is that the integers and strings are not matching up, as you can see in this screenshot here:

example html table

if anyone can make sense of why the output is so screwed up that would be appreciated! if there’s any more information that you need to answer my question I’ll gladly add it.

edit

for the record at the top of the screenshot the unbanned_in timestamp is 1320247970 if I run that through my function this is the result I get

>>> ban = session.query(db.Ban).filter_by(id=3783).one()
>>> print ban.unbanned_in('int'), ban.unbanned_in('readable')
0000049044 2 days, 13:37:24.179045
  • 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-26T11:40:12+00:00Added an answer on May 26, 2026 at 11:40 am

    If you want to get the number of seconds between time and now, use

    remaining.days * 24 * 3600 + remaining.seconds
    instead of just remaining.seconds

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My web application generates reports and I need now to add the print preview
The web application that I am developing right now has something called quiz engine
My web application contains a text box for which I would like to restrict
My web application uses the same database configuration as the application XYZ. I have
Web application storing images in database. In our first setup we were storing (and
The web application that I am developing right now has something called quiz engine
NET web application and a WCF Application that share the same ASP.NET membership database.
My web application is using redis for the main database. It's very nice in
My web application retrieves the location of an image from database. I'd like to
My web application is receiving increased attention and I need to provide additional security

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.