• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 371
  • Last Modified:

year 5 years ago

How to find a year which was 5 years ago  in PHP.

Like now we have 2011. I would like to have my starting year as "06" (with leading zeros)
0
Rozamunda
Asked:
Rozamunda
  • 3
  • 2
  • 2
1 Solution
 
jSherzCommented:
<?php

echo(date("Y") - 5);

?>

Open in new window

0
 
stu215Systems AnalystCommented:
Are you searching a database? array? textfile?

What is your dateformat?
0
 
RozamundaAuthor Commented:
jsherz:    it shows 69 ( ???)


stu215: i want to get "06" for the current year, next year i would like to get "07" .


What do you mean date format ? in php.ini ?
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
jSherzCommented:
stu215: That's odd - on my installation it shows 2006.

Try this:
<?php

        $current_year = (int)date("Y");
        $current_year = $current_year - 5;
        echo($current_year);
?>

Open in new window

0
 
RozamundaAuthor Commented:
i found the solution myself:


  echo       date("y",strtotime('now - 5 years'));


jSherz - it would not work if the date was 2003
0
 
stu215Systems AnalystCommented:
Using date() :

Y  = A full numeric representation of a year, 4 digits Examples: 1999 or 2003
y  = A two digit representation of a year Examples: 99 or 03
0
 
RozamundaAuthor Commented:
the provided solutions did not answer my question
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now