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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:14:35+00:00 2026-05-23T04:14:35+00:00

Hi im trying to compare two dates in MySQL via a query, one is

  • 0

Hi im trying to compare two dates in MySQL via a query, one is a date when an article was first posted and the second date is for when it should be removed by the query (after 365 days, ran by a cron task every 30 minutes.), below is my SQL query

DELETE FROM $wpdb->posts WHERE post_type = 'business' AND DATEDIFF(NOW(), post_date_gmt) > 2 

My date is held in the database in this format 2011-05-26 13:10:56 so my question is will the DATETIME query honour the exact date and time or when cron is ran at the 365th day delete the article even if there are still 13:10:56 left before it is actually 365 days old?

Regards

  • 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-23T04:14:36+00:00Added an answer on May 23, 2026 at 4:14 am

    Your query, as written, will delete any posts older than 2 days–not 365.

    But the answer to your question is easy to test:

    mysql> SELECT DATEDIFF('2011-01-01 00:10:00','2011-01-01 00:00:00');
    +-------------------------------------------------------+
    | DATEDIFF('2011-01-01 00:10:00','2011-01-01 00:00:00') |
    +-------------------------------------------------------+
    |                                                     0 | 
    +-------------------------------------------------------+
    1 row in set (0.00 sec)
    

    As you can see, DATEDIFF() returns only whole days, as an integer. A similar test with ‘2011-01-01 23:59:59’ as the first date will also yield 0.

    So the short answer to your question is “Yes, it honors the date and time, down to the second.”

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

Sidebar

Related Questions

I trying to compare two dates (DateTime) in nHibernate linq: query = query.Where(l =>
I'm trying to compare two dates in PHP and figure out how many days
I am trying to compare two dates. I have this code which I thought
im trying to compare two dates like this ICriteria criteria = base.DataStore.TransactionScope.NHibernateSession.CreateCriteria<CcCorte>(); criteria.Add(Restrictions.Ge(Start, init.Date));
I am trying to compare two dates which are in Finnish time form like
I am having a problem when i am trying to compare two dates in
I'm trying to compare two variables of type nullable(of boolean) in VB.NET 2010. One
I am trying to compare two decimal values in Java script. I have two
I am trying to compare two .caf files on the basis of some parameter,
I'm trying to compare two strings with each other on the iphone, but the

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.