gerkintrigg Posted May 5, 2007 Share Posted May 5, 2007 Hiya. I'm trying to work out what the best way is to find the difference between dates. I have it in a variable so i think something like this should work... (Pseudo code only... i know the syntax etc is wrong) if ((current_date-start_date)>=4weeks){ // if the start date is more than 4 weeks away: price=(price/3); } any suggestions would be really helpful. thanks. Quote Link to comment https://forums.phpfreaks.com/topic/50114-subtracting-dates/ Share on other sites More sharing options...
c_shelswell Posted May 5, 2007 Share Posted May 5, 2007 The best way to do this is to convert them in to unix timestamps then you can easily add and subtract them i think what you're looking for is "strtotime" so get your date then find out what 4 weeks in advance is so i guess 60*60*24*31 i think gives you a month of seconds. Hope this helps Quote Link to comment https://forums.phpfreaks.com/topic/50114-subtracting-dates/#findComment-246051 Share on other sites More sharing options...
gerkintrigg Posted May 5, 2007 Author Share Posted May 5, 2007 cool thanks, I'm trying to use this: if (($my_date_now-strtotime($start_date))<=(strtotime(+4 weeks,$my_date_now)-$my_date_now)){ $deposit_payable } it returns: Parse error: syntax error, unexpected T_STRING in /home/tichborn/public_html/includes/date_check_2.php on line 50 I know what the problem is, but not how to resolve it. Could someone help please? Quote Link to comment https://forums.phpfreaks.com/topic/50114-subtracting-dates/#findComment-246060 Share on other sites More sharing options...
c_shelswell Posted May 5, 2007 Share Posted May 5, 2007 I take it the "$my_date_now" variable is a unix timestamp not a date? Perhaps a silly question. Quote Link to comment https://forums.phpfreaks.com/topic/50114-subtracting-dates/#findComment-246063 Share on other sites More sharing options...
gerkintrigg Posted May 5, 2007 Author Share Posted May 5, 2007 yeah, time(); Quote Link to comment https://forums.phpfreaks.com/topic/50114-subtracting-dates/#findComment-246071 Share on other sites More sharing options...
c_shelswell Posted May 5, 2007 Share Posted May 5, 2007 could you paste the chunk of your actual code. I think the problem might be this bit: "strtotime(+4 weeks,$my_date_now)" what i would do is have: $future_date = $my_date_now + 2678400; //this gives 4 weeks in the future you can then have if (($my_date_now-strtotime($start_date))<=(strtotime($future_date)-$my_date_now)){ $deposit_payable; // i noticed you never had the ";" there } if you paste the actual code it might be easier. Cheers Quote Link to comment https://forums.phpfreaks.com/topic/50114-subtracting-dates/#findComment-246083 Share on other sites More sharing options...
gerkintrigg Posted May 7, 2007 Author Share Posted May 7, 2007 In the end i did this: $my_date_now=time(); $future_date = strtotime('+4 weeks',$my_date_now); if (($start_date-$future_date)>=0){ $deposit_payable='y'; } Thanks for the pointer though. Quote Link to comment https://forums.phpfreaks.com/topic/50114-subtracting-dates/#findComment-247219 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.