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

Code to display "next" year dynamically in PHP

Hello,

I'm converting a script from Coldfusion to PHP.  One of the lines of code dynamically returns "next" year.

In Coldfusion, the code is #DateFormat(DateAdd('YYYY',1,now()),"YYYY")#

What is the PHP equivalent?  So at the time of this writing, it would return "2016".

Thanks in advance.
0
benjaminfam
Asked:
benjaminfam
  • 2
  • 2
2 Solutions
 
gr8gonzoConsultantCommented:
Check out this good article on date/time handling in PHP. It should give you your answer and help you with the conversion process.

http://www.experts-exchange.com/Programming/Languages/Scripting/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html
0
 
Radek BaranowskiFull-stack Java DeveloperCommented:
<?php

echo date("Y")+1;

?>

Open in new window

0
 
gr8gonzoConsultantCommented:
Radek is correct, but I was trying to teach you how to fish. :) Please read through that article - it will give you a lot more insight into what you can do with date/time in PHP than just next year. If you're converting an application, it's pretty vital information.
0
 
Radek BaranowskiFull-stack Java DeveloperCommented:
upvoting what gonzo said. :)
0
 
benjaminfamAuthor Commented:
Thank you both.  This was very helpful.   I do know how to fish, but sometimes circumstances just  necessitate a quick answer.  I had actually done some "fishing" yesterday, but was over complicating it a bit apparently by trying to use the mktime() function in conjunction with the date() function.   I appreciate the simplicity that you offered and I do in fact appreciate the link and will read it in its entirety as it's ultimately my desire to grow in my knowledge and understanding.  Sometimes time is of the essence thought.  :-)
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 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.

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