sotusotusotu Posted May 3, 2009 Share Posted May 3, 2009 Hi guys, I have a datetime field in my database which stores a datetime value. I basically need to find if it has been exactly a week after the entry. Retreiving this data is not the problem as I have done this with SQL. My issue is trying to find out if the 7 interval query is actually greater than the original query by more than 7 days. For example if the original value is: 2009-05-03 22:07:59 and the +7 Day interval is: 2009-05-10 22:07:59, how can I find out if the second is great by 7 days? Can anyone please give me an example of how to do this, or point me in the right diffection? Cheers Quote Link to comment https://forums.phpfreaks.com/topic/156715-determine-how-long-between-dates/ Share on other sites More sharing options...
Ken2k7 Posted May 3, 2009 Share Posted May 3, 2009 SQL has DATEDIFF(). Use that. By the way, if you don't mind me asking, is there a meaning behind sotusotusotu? (In reference to your name.) Quote Link to comment https://forums.phpfreaks.com/topic/156715-determine-how-long-between-dates/#findComment-825228 Share on other sites More sharing options...
sotusotusotu Posted May 4, 2009 Author Share Posted May 4, 2009 Hi Ken2K7, Sotusotusotu doesn't mean anything. I think originally it started as 'sotu' when opening up a an email account many moons ago; then as passwords were forgotten, extra sotu's where added to the end. Cheers for you suggestions but I just having just tried the datediff function, it didn't seem to calculate the difference between the days/hours correctly. For example if you try exactly -7 days difference: SELECT DATEDIFF( '2009-04-26 22:07:59', '2009-05-03 22:07:59' ) FROM `letters` AS DiffDate The result is -7days. However if you just change the time values in the 2nd datetime value to a couple of hours earlier, which should be the previous day, I still '-7days' as the result. Surely this is incorrect and should return -6 days?! For example: SELECT DATEDIFF( '2009-04-26 22:07:59', '2009-05-03 20:07:59' ) FROM `letters` AS DiffDate Any other suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/156715-determine-how-long-between-dates/#findComment-825243 Share on other sites More sharing options...
Ken2k7 Posted May 4, 2009 Share Posted May 4, 2009 You wanted to find if the date diff is a week or 7 days right? So... what's the problem? 2 hours behind still isn't 7 days. Quote Link to comment https://forums.phpfreaks.com/topic/156715-determine-how-long-between-dates/#findComment-825245 Share on other sites More sharing options...
sotusotusotu Posted May 4, 2009 Author Share Posted May 4, 2009 What you are saying is completely true Ken. Thank you for pointing that my reply was completely stupid . It's after 1 in the morning here so I think I might put down the computer and stop asking silly questions and leave this for the night. Cheers for the help mate. Quote Link to comment https://forums.phpfreaks.com/topic/156715-determine-how-long-between-dates/#findComment-825252 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.