Solved

mktime, back a month

Posted on 2003-11-30
2
233 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 50 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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses how to implement server side field validation and display customized error messages to the client.
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…
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.

688 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