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 477895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:38:13+00:00 2026-05-13T00:38:13+00:00

I am working on an application that needs to handle expiring airline miles. The

  • 0

I am working on an application that needs to handle expiring airline miles. The miles can be used, but if they are not used by a certain date, they will expire. I want to make sure I expire the proper amount of miles but don’t expire them if they have been used. Therefore, I have to check if enough miles have been used in a given date range before they expire. Here are my initial thoughts:

Have a miles table with the following columns:

  • user_id – Foreign key to the users table
  • number_miles – The number of miles for this record
  • miles_type – Indicates if miles were added, used, or expired
  • miles_expire – Boolean value to indicate if these miles expire or not
  • miles_date – The date this record was added
  • exipration_date – The date these miles expire (if the miles_expire flag is true)
  • processed – Indicates if this record has been processed – only applicable when the miles_type is set to expire

If I have a record every time miles are added, used, or expired from a particular user account, I figure I can calculate the expired miles as such:

  1. For each user, get the dates of the records where the miles_expire flag set to true, the expiration_date is before the current date, and the processed flag is set to false. This will get the records for all miles that should be expired.
  2. Get the first and last expiration_date from the previous query.
  3. Using the first and last expiration_date values from the previous step, get a list of all used miles within that date range.
  4. If the sum of the used miles from the previous step is less than the sum of the expiring points, expire the difference. If the used miles are equal or greater, nothing has to be expired.
  5. Set the processed flag to true for all records within the first and last expiration_date range. Either these miles have been expired or ignored as they have been used.

It appears this meets the following requirements:

  • Expiring miles are used first
  • It will only check the used miles for the same time frame as the used miles so using many miles in the past won’t save future miles from expiring
  • Miles are only expired after the date and won’t be if the user has used enough miles

Are there other considerations I need to take into account? Will this work to properly expire miles?

  • 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-13T00:38:13+00:00Added an answer on May 13, 2026 at 12:38 am

    Your method won’t work for several reasons. The easiest to explain is probably this:

    For each user, get the dates of the records where the miles_expire flag set to true, the expiration_date is before the current date, and the processed flag is set to false. This will get the records for all miles that should be expired.

    Note that this could be only one record. If you run your check very often, it will typically be only one record in fact. Let’s assume for simplicity that max one record expires each day (if more than one expires, your algorithm still fails, it’s just harder to explain).

    Get the first and last expiration_date from the previous query.

    You’ll get the same date here, because there’s only one record.

    Using the first and last expiration_date values from the previous step, get a list of all used miles within that date range.

    Since first and last are equal, there is no range and so there will never be used miles in that range.

    If the sum of the used miles from the previous step is less than the sum of the expiring points, expire the difference. If the used miles are equal or greater, nothing has to be expired.

    Since the previous step returned no rows, the sum is zero, so you will always expire the difference between ‘expired miles’ and ‘0’. Even if the miles have been used.

    This process will repeat.

    Overall your design seems unnecessarily compilcated. I would just store a list of unused vouchers for each user. When they pay, vouchers used are marked as used. If a voucher is half used, it is marked as used and a new voucher is issued with the same expiration date, but with a smaller amount. If there are more vouchers than needed, soon to expire vouchers are used up first, and non-expiring vouchers are used last. Vouchers that have expired can never be used for payment, so you don’t need to do anything to expire them.

    So in summary: you don’t need to expire any vouchers, just make sure the payment code does not allow usage of expired or used vouchers.

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

Sidebar

Related Questions

I am working on a Rails application that needs to handle dates and times
I'm working on an application that needs to notify the user when they receive
Im working on an application that needs to talk to a database. The application
I'm working on an application that needs to convert an HTML workspace (fixed size
I'm working on an application that needs to get the source of a web
i am working on an application that needs to scan bar codes as a
I am working on an Android application that needs to determine the current tee
I'm working on a multi-monitor kiosk application that needs to run full-screen on both
REASON: I'm working on an emergency alert application that needs to display information on
I'm working on early designs for an application that needs to start out small

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.