Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-06-2013, 09:56 PM   PM User | #1
sitechooser
New Coder

 
Join Date: Jan 2013
Posts: 16
Thanks: 6
Thanked 0 Times in 0 Posts
sitechooser is an unknown quantity at this point
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.
sitechooser is offline   Reply With Quote
Old 01-06-2013, 11:30 PM   PM User | #2
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
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
AndrewGSW is offline   Reply With Quote
Users who have thanked AndrewGSW for this post:
sitechooser (01-09-2013)
Old 01-07-2013, 11:09 PM   PM User | #3
sitechooser
New Coder

 
Join Date: Jan 2013
Posts: 16
Thanks: 6
Thanked 0 Times in 0 Posts
sitechooser is an unknown quantity at this point
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..
sitechooser is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:03 PM.


Advertisement
Log in to turn off these ads.