Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jan 2013
    Posts
    17
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Comparing 2 dates

    Hi Everyone,

    I need to compare 2 date fields in my MySQL database (date1 and date2) to see if they are more than 28 days apart.

    Can anyone help with suggestions for the correct MySQL query?

    Thanks very much indeed.

  • #2
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    A little searching tells me:

    PHP Code:
    "SELECT stuff FROM my_table WHERE DATEDIFF(date2,date1) > 28"
    //or 

    "SELECT date1, date2, DATEDIFF(date2,date1) AS difference FROM my_table"
    // extract into $row..
    if (intvar($row['difference'], 10) > 28) {
        
    // do more stuff 
    but I haven't tried them. See the docs.
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • Users who have thanked AndrewGSW for this post:

    sitechooser (01-09-2013)

  • #3
    New Coder
    Join Date
    Jan 2013
    Posts
    17
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Massive thank you, Sir! I will let you know how I get on with that

    Edit: Worked like a dream! I shall remember you when I'm a millionaire!
    Last edited by sitechooser; 01-07-2013 at 11:23 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •