943,520 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 1284
  • PHP RSS
Mar 23rd, 2009
0

date variable plus 1 error(pls help)

Expand Post »
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:
php Syntax (Toggle Plain Text)
  1. $nowdate = date('Y') "-" date('Y') + 1;
  2. echo $nowdate;

Thank you for giving time this simple problem.

God bless on this mother earth.
Last edited by blocker; Mar 23rd, 2009 at 1:43 am.
Similar Threads
Reputation Points: 7
Solved Threads: 1
Posting Whiz in Training
blocker is offline Offline
231 posts
since Jan 2009
Mar 23rd, 2009
1

Re: date variable plus 1 error(pls help)

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

php Syntax (Toggle Plain Text)
  1. $nowdate = date('Y') . "-" . (date('Y') + 1);
Reputation Points: 395
Solved Threads: 192
Veteran Poster
darkagn is offline Offline
1,136 posts
since Aug 2007
Mar 23rd, 2009
0

Re: date variable plus 1 error(pls help)

This may not be the best way to do it, but it should work
php Syntax (Toggle Plain Text)
  1. $thisYear = date('Y');
  2. $nextYear = $thisYear + 1
  3. $nowdate = $thisYear "-" $nextYear;
I really need to go to sleep
Reputation Points: 96
Solved Threads: 124
Master Poster
Will Gresham is offline Offline
728 posts
since May 2008
Mar 23rd, 2009
0

Re: date variable plus 1 error(pls help)

Click to Expand / Collapse  Quote originally posted by xan ...
This may not be the best way to do it, but it should work
php Syntax (Toggle Plain Text)
  1. $thisYear = date('Y');
  2. $nextYear = $thisYear + 1
  3. $nowdate = $thisYear "-" $nextYear;
I really need to go to sleep
Ive just made a little adjustment of the code you've given and it works. below is the code:

php Syntax (Toggle Plain Text)
  1. $thisYear = date('Y');
  2. $nextYear = $thisYear + 1;
  3. $nowdate = $thisYear ."-". $nextYear;
  4. 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.
Last edited by blocker; Mar 23rd, 2009 at 2:05 am.
Reputation Points: 7
Solved Threads: 1
Posting Whiz in Training
blocker is offline Offline
231 posts
since Jan 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: SQL Statement in PHP
Next Thread in PHP Forum Timeline: All my buttons with javascript dont work.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC