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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:59:39+00:00 2026-06-18T09:59:39+00:00

I am working on a auto listing website and i am stuck at some

  • 0

I am working on a auto listing website and i am stuck at some logic behind how to get the dates right.

I have created a sql fiddle for the database
http://www.sqlfiddle.com/#!2/e111e/3

I want to run a cron every day at 12 AM and i want to email the users whoselistings which are going to expire (ignores already expired ones) in a day but there must be a 24 hour difference between them as I want to tell them minimum 24 hours in advance that there listing is going to be expired. Also it should select only those listings which are going to be expire after one day only and not more than 1 day.

Here is what i tried so far

SELECT DATE_FORMAT(expiry_date, '%b %d %Y %T') AS expiry_date, DATEDIFF(expiry_date, NOW()) AS days_left FROM `test` WHERE DATEDIFF(expiry_date, NOW()) = 1

but it is also selecting which are going to expire in less than 24 hours.

Please help me with it.

EDIT
///////////////////////////////////////////////////////////////

I have figured out this. Tell me guys if its correct or not.

 SELECT DATE_FORMAT(expiry_date, '%b %d %Y %T') AS expiry_date, DATEDIFF(expiry_date, NOW()) AS days_left, HOUR(TIMEDIFF(expiry_date, NOW())) as hours FROM `test`

WHERE
DATEDIFF(expiry_date, NOW()) = 1 AND HOUR(TIMEDIFF(expiry_date, NOW())) > 24

  • 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-06-18T09:59:40+00:00Added an answer on June 18, 2026 at 9:59 am

    MySQL’s datediff only takes into account the actual days, not the hours. Try to work with TO_SECONDS and take the difference as seconds.

    UPDATE: and this is the code which works with the fiddle:

    SELECT DATE_FORMAT(expiry_date, '%b %d %Y %T') AS expDate,
      to_seconds(expiry_date) - to_seconds(NOW()) AS seconds_left
    FROM `test`
    WHERE
      to_seconds(expiry_date)- to_seconds(now()) <= 86400
      -- AND ... (only include non-expired entries)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have managed to get code the knockoutJS jqauto auto-complete working as per the
I'm working on databases that have moving tables auto-generated by some obscure tools. By
I am working on a website that auto populates search result in a table
I have installed Eclipse Indigo and the auto-complete feature is working normally in the
I am working on an auto trade website. On the page where Ad list
I have auto registration working with authlogic using gaizka's version of authlogic_openid which I
I'm working on an auto-reload feature for WHIFF http://whiff.sourceforge.net (so you have to restart
I'm working on a jQueryMobile application with some form fields that need auto complete
I working on an auto synchronization project where I want to get the data
Ive been trying to get the VIM auto completion working, but am running into

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.