?
Solved

mktime, back a month

Posted on 2003-11-30
2
Medium Priority
?
235 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

765 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