Jump to content

subtract a month from a date()


Paul-D

Recommended Posts

Do I relay have to do all this in PHP 5.0?

<?php
$Date = time();
$Month = date('m' ,$Date);
$Year = date('Y' ,$Date);
$Month -= 1;
if ($Month == 0)
  {
   $Month = 12;
   $Year -= 1;
  }
$Date = $Year . "-" . $Month . "-01";
echo $Date;
?>

Link to comment
Share on other sites

Thanks
echo date('Y-m-d', strtotime('first day of last month')); 
is beeter than

$date = new DateTime('first day of last month');

But how do I get a php.ini into the system for future class related programming

I have
[Date]
date.timezone=Europe/London
 

Will it be picked up automatically or as a shared server be ignored?

 

Edited by Paul-D
Link to comment
Share on other sites

As I had to do, you should contact your hosting support people and TELL them you want your PHP.ini file to indicate the timezone that you want to default to.  Then you'll never have to worry about it again.  If they tell you that you can't have it that way, then tell them to give you a FULL copy of the existing .ini file that is in use where you can access it and make the change(s) you need.  Be careful though!

Link to comment
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.