954,585 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

date variable plus 1 error(pls help)

good day.!

I want this date format to be echo. 2009-2010. My code gots error when i try to show this format. Here is my code:

$nowdate = date('Y') "-" date('Y') + 1;
echo $nowdate;


Thank you for giving time this simple problem.

God bless on this mother earth.

blocker
Posting Whiz in Training
232 posts since Jan 2009
Reputation Points: 7
Solved Threads: 1
 

I assume you want $nowdate to be a string. String concatenation in PHP uses a period character to join strings. This **should** work:

$nowdate = date('Y') . "-" . (date('Y') + 1);
darkagn
Veteran Poster
1,197 posts since Aug 2007
Reputation Points: 404
Solved Threads: 200
 

This may not be the best way to do it, but it should work

$thisYear = date('Y');
$nextYear = $thisYear + 1
$nowdate = $thisYear "-" $nextYear;

I really need to go to sleep :D

Will Gresham
Master Poster
755 posts since May 2008
Reputation Points: 96
Solved Threads: 125
 

This may not be the best way to do it, but it should work

$thisYear = date('Y');
$nextYear = $thisYear + 1
$nowdate = $thisYear "-" $nextYear;

I really need to go to sleep :D

Ive just made a little adjustment of the code you've given and it works. below is the code:

$thisYear = date('Y');
$nextYear = $thisYear + 1;
$nowdate = $thisYear ."-". $nextYear;
echo $nowdate;


Thank many very much.

The first reply shows nothing on the browser but I use his technique to concantinate the string and echo it.

Thank you to all.

blocker
Posting Whiz in Training
232 posts since Jan 2009
Reputation Points: 7
Solved Threads: 1
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You