View Full Version : If Date sentence with PHP

11-24-2010, 09:51 AM
I like to perform IF sentence like:

if {($today = date("H")+12>12) echo date("d.m.Y", strtotime ('+1 days'));
echo 'in'.date("d.m.Y", strtotime ('+2 days'))}else {echo date("d.m.Y", strtotime ('+0 days')); echo ' in '.date("d.m.Y", strtotime ('+1 days'))}; ?>

What is issue with this?:)

11-24-2010, 01:22 PM
maybe you should do

if ($today = date("H")+12>12) { ...

11-24-2010, 02:02 PM
Seems some issue with IF.

It gives me an error (missing ; or ,):

<?PHP if ($today = date("H")+12>12){echo date("d.m.Y", strtotime ('+1 days'))echo 'in' date("d.m.Y", strtotime ('+2 days'))} else {echo date("d.m.Y", strtotime ('+0 days')) echo 'in' date("d.m.Y", strtotime ('+1 days'))}; ?>

11-24-2010, 02:16 PM
First off your IF is not doing what you expect. The comparison operator is == not a single =. What you are doing there is assigning a value to $today which is probably not what you want to do. You are also trying, it looks like, to compare 2 things. Do you want $today to be the current hour plus 12? What is the > 12 in there for?

What you posted had numerous syntax errors so I cleaned it up so it's valid though it probably isn't going to echo things exactly like you'd like. And there is still the issue of exactly what you were trying to do with the IF statement.

if ($today == date("H") > 12){

echo date("d.m.Y", strtotime ('+1 days'));
echo 'in' . date("d.m.Y", strtotime ('+2 days'));

} else {

echo date("d.m.Y", strtotime ('+0 days'));
echo 'in' . date("d.m.Y", strtotime ('+1 days'));

} ?>

11-24-2010, 03:01 PM
Hi, I have issue as I like to define date but it depends 12 hours time zone.
How to do code like:

echo date("d.m.Y");

But added Timezone GMT +12?
Date should be changed...

11-24-2010, 03:13 PM
I don't understand what you are asking or trying to do at all.

11-24-2010, 06:49 PM
if you want to define $today variable the you could try this

if (($today = date("H")+12) > 12) {
echo $today;

11-25-2010, 09:37 AM
I like to define Timezone time like GMT+12