?
Solved

mktime, back a month

Posted on 2003-11-30
2
Medium Priority
?
237 Views
Last Modified: 2006-11-17

Hi,

I need to go back a month, then another, then another, etc.  I thought it went something like:

$date1 = date("M_y",mktime(0,0));
$date2 = date("M_y",mktime(-1,0));
$date3 = date("M_y",mktime(-2,0));
$date4 = date("M_y",mktime(-3,0));

but I obviously don't know what I am doing, I get: Dec_03, Nov_03, Nov_03, Nov_03 as the results.  What I need to get is: Dec_03, Nov_03, Oct_03, Sep_03.

What do I need to do to fix?

Thanks,  Chris


0
Comment
Question by:ChrisAndrews
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 13

Accepted Solution

by:
lozloz earned 200 total points
ID: 9848420
hi,

probably the easiest but not quite so technical way:

<?
$date1 = date("M_y"); // the current date in the format Dec_03
$date2 = strtotime("-1 month"); // timestamp of current date - 1 month
$date3 = strtotime("-2 month"); // timestamp of current date - 2 months
$date4 = strtotime("-3 month"); // timestamp of current date - 3 months
$date2 = date("M_y", $date2); // formatted string of 1 month back
$date3 = date("M_y", $date3); // formatted string of 2 months back
$date4 = date("M_y", $date4); // formatted string of 3 months back
?>

cheers,

loz
0
 

Author Comment

by:ChrisAndrews
ID: 9848481

Thank you loz, works great :)

Chris
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question