Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    May 2006
    Posts
    216
    Thanks
    4
    Thanked 0 Times in 0 Posts

    If Date sentence with PHP

    I like to perform IF sentence like:
    PHP Code:

    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?

  • #2
    Regular Coder poyzn's Avatar
    Join Date
    Nov 2010
    Posts
    266
    Thanks
    2
    Thanked 61 Times in 61 Posts
    maybe you should do
    PHP Code:
    if ($today date("H")+12>12) { ... 

  • #3
    Regular Coder
    Join Date
    May 2006
    Posts
    216
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Question

    Seems some issue with IF.

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

    <?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'))}; ?>

  • #4
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,300
    Thanks
    4
    Thanked 203 Times in 200 Posts
    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.

    PHP Code:
    <?php
    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'));

    ?>
    Dave .... HostMonster for all of your hosting needs

  • #5
    Regular Coder
    Join Date
    May 2006
    Posts
    216
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Question

    Hi, I have issue as I like to define date but it depends 12 hours time zone.
    How to do code like:
    PHP Code:

    echo date("d.m.Y"); 
    But added Timezone GMT +12?
    Date should be changed...

  • #6
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,300
    Thanks
    4
    Thanked 203 Times in 200 Posts
    I don't understand what you are asking or trying to do at all.
    Dave .... HostMonster for all of your hosting needs

  • #7
    Regular Coder poyzn's Avatar
    Join Date
    Nov 2010
    Posts
    266
    Thanks
    2
    Thanked 61 Times in 61 Posts
    if you want to define $today variable the you could try this
    PHP Code:
    if (($today date("H")+12) > 12) { 
       echo 
    $today;


  • #8
    Regular Coder
    Join Date
    May 2006
    Posts
    216
    Thanks
    4
    Thanked 0 Times in 0 Posts
    I like to define Timezone time like GMT+12


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •