mat-tastic Posted October 1, 2008 Share Posted October 1, 2008 Hey Guys, I have never had to do this before, but someone wants me to help them. I have done the rest of the coding for the system, however: The client has to renew their server (TS Server) and two weeks after that the renew deadline day, they want the servers to be removed if they have not renewed in that two weeks. How would I work out when two weeks has passed from the renew date? e.g two weeks after 2008/06/05 Link to comment https://forums.phpfreaks.com/topic/126655-comparing-two-date-values/ Share on other sites More sharing options...
Zhadus Posted October 1, 2008 Share Posted October 1, 2008 What format is the date in, the automatic MySQL datestamp? Link to comment https://forums.phpfreaks.com/topic/126655-comparing-two-date-values/#findComment-654983 Share on other sites More sharing options...
severndigital Posted October 1, 2008 Share Posted October 1, 2008 i have just been working on a somewhat similar issue myself. some question need to be answered first for the easiest solution. 1. what version of php are you using? 2. how is the date stored now? 3. how automated does this need to be? (i.e. is this script going to run on it's own at a given time?, or will the user manually run the script?) I ask what version of PHP you have because there are inherent classes for dealing with Date and Time in 5.2.x Answer those up and we can figure something out for you.! -C Link to comment https://forums.phpfreaks.com/topic/126655-comparing-two-date-values/#findComment-654988 Share on other sites More sharing options...
mat-tastic Posted October 1, 2008 Author Share Posted October 1, 2008 It uses DATE_ADD(NOW(), INTERVAL 2 WEEK) to store the renew date, I need to work out, the date two weeks after that. Thanks for your help so far. Link to comment https://forums.phpfreaks.com/topic/126655-comparing-two-date-values/#findComment-655034 Share on other sites More sharing options...
discomatt Posted October 1, 2008 Share Posted October 1, 2008 Assuming you're storing DATE_ADD(NOW(), INTERVAL 2 WEEK) into `dateColumn` DATE_ADD(`dateColumn`, INTERVAL 2 WEEK) Link to comment https://forums.phpfreaks.com/topic/126655-comparing-two-date-values/#findComment-655055 Share on other sites More sharing options...
revraz Posted October 1, 2008 Share Posted October 1, 2008 Yep, do it in SQL and not PHP. Link to comment https://forums.phpfreaks.com/topic/126655-comparing-two-date-values/#findComment-655068 Share on other sites More sharing options...
mat-tastic Posted October 1, 2008 Author Share Posted October 1, 2008 Sorry not to sure i understand what you mean? The script would be run manually. It just needs to check what date it would be if it was two weeks after the renewal data in the database, then compare that to the current date. if the current date is equal or past it, it kills the server. Link to comment https://forums.phpfreaks.com/topic/126655-comparing-two-date-values/#findComment-655074 Share on other sites More sharing options...
discomatt Posted October 1, 2008 Share Posted October 1, 2008 SELECT `account` FROM `table` WHERE DATE_ADD(`expires`, INTERVAL 2 WEEK) > NOW() Any rows that are returned have an `expires` value older than 2 weeks. Link to comment https://forums.phpfreaks.com/topic/126655-comparing-two-date-values/#findComment-655079 Share on other sites More sharing options...
mat-tastic Posted October 1, 2008 Author Share Posted October 1, 2008 Thank you I will try it! Link to comment https://forums.phpfreaks.com/topic/126655-comparing-two-date-values/#findComment-655121 Share on other sites More sharing options...
Barand Posted October 1, 2008 Share Posted October 1, 2008 SELECT `account` FROM `table` WHERE DATE_ADD(`expires`, INTERVAL 2 WEEK) > NOW() Any rows that are returned have an `expires` value older than 2 weeks. if expires + 2 week > now() then the records are younger than 2 weeks for older than 2 weeks you are looking for expires < NOW() - INTERVAL 2 WEEK Link to comment https://forums.phpfreaks.com/topic/126655-comparing-two-date-values/#findComment-655184 Share on other sites More sharing options...
mat-tastic Posted October 2, 2008 Author Share Posted October 2, 2008 SELECT `account` FROM `table` WHERE DATE_ADD(`expires`, INTERVAL 2 WEEK) > NOW() Any rows that are returned have an `expires` value older than 2 weeks. if expires + 2 week > now() then the records are younger than 2 weeks for older than 2 weeks you are looking for expires < NOW() - INTERVAL 2 WEEK Thanks to both of you, I will report back shortly. Link to comment https://forums.phpfreaks.com/topic/126655-comparing-two-date-values/#findComment-655287 Share on other sites More sharing options...
discomatt Posted October 2, 2008 Share Posted October 2, 2008 Thanks for spotting that Barand. Got my mouth facing the wrong way Link to comment https://forums.phpfreaks.com/topic/126655-comparing-two-date-values/#findComment-655310 Share on other sites More sharing options...
mat-tastic Posted October 2, 2008 Author Share Posted October 2, 2008 Can I just confirm it would be this: SELECT `account` FROM `table` WHERE DATE_ADD(`expires`, NOW()) < INTERVAL 2 WEEK Link to comment https://forums.phpfreaks.com/topic/126655-comparing-two-date-values/#findComment-655559 Share on other sites More sharing options...
mat-tastic Posted October 2, 2008 Author Share Posted October 2, 2008 I got it working with: "SELECT * FROM `servers` WHERE DATE_ADD(`renew_date`, INTERVAL 2 WEEK) < CURDATE()"; Can someone explain to me how that works? To me it looks like the < should be > ???? Link to comment https://forums.phpfreaks.com/topic/126655-comparing-two-date-values/#findComment-655732 Share on other sites More sharing options...
Zhadus Posted October 2, 2008 Share Posted October 2, 2008 The current date is LATER, and therefore a HIGHER number than the renew date. Therefore you'd want it LESS THAN the current date by an interval of 2 weeks. Hope that makes sense. Link to comment https://forums.phpfreaks.com/topic/126655-comparing-two-date-values/#findComment-655737 Share on other sites More sharing options...
Barand Posted October 2, 2008 Share Posted October 2, 2008 I find it easier to think of it as "where renewdate < the date 2 weeks ago" i.e. "SELECT * FROM `servers` WHERE `renew_date` < CURDATE() - INTERVAL 2 WEEK"; Link to comment https://forums.phpfreaks.com/topic/126655-comparing-two-date-values/#findComment-655834 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.