TheBlackBenzKid
TheBlackBenzKid

Reputation: 27087

PHP if Time or Date Greater than Show Echo

This code does not want to compile. So I tried making the time text into a string.

$swnow = date('10:00:01');
$vsp=$swnow;
echo $vsp;

if ($vsp > '10:00:01') {echo 'greater than 10';}

I want an action if my server is visited at 10am.

Upvotes: 1

Views: 4850

Answers (5)

T.Todua
T.Todua

Reputation: 56351

If you have like this, then you can use :

if ( $mydate > strtotime('2013-03-19 17:14:40') ){
echo 'Hello';
}

Upvotes: 0

Sergiy Shulyar
Sergiy Shulyar

Reputation: 1

<?php
$Date = date('H:i:s');
if($Date > '10:00:01'){
    echo 'less than 10';
} else {
    echo 'bla-bla-bla';
}
?>

Upvotes: 0

David B&#233;langer
David B&#233;langer

Reputation: 7438

If you wanna work with real time use this but I will much more consider working with UNIX_TIMESTAMP :

$Date = date('H', strtotime('10:00:01'));
if($Date > 10){
    echo 'Well, 11, 12, 13, 14 ... till 23';
} else {
    echo 'Maybe it is 00, 01, 02, 03, 04, 05, 06, 07, 08, 09 or 10 hours AM.';
}

Upvotes: 1

TheBlackBenzKid
TheBlackBenzKid

Reputation: 27087

My own solution to this, to avoid GMT response and server drain. Use JavaScript universal) v8 engine.

<script type="text/javascript">
<!--
    var currentTime = new Date()
    var hours = currentTime.getHours()
    var minutes = currentTime.getMinutes()

    //hours between 10am and 16pm
    if (hours>10){
        if (hours<16){
            document.write("phone anim");
        }else{
            document.write("phone static")
        }
    }

//-->
</script>

Upvotes: 0

Oyeme
Oyeme

Reputation: 11225

Use strtotime() function to convert string to time.

Upvotes: 0

Related Questions