Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/50114-subtracting-dates/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/50114-subtracting-dates/#findComment-246051
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/50114-subtracting-dates/#findComment-246060
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/50114-subtracting-dates/#findComment-246083
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.