PHP If/else statement with formatted date to determine the part of the day -
If I'm trying to simplify the /seb statement in PHP. Think simple like this:
& lt ;? Php $ time = 13; If ($ time & lt; 12) {echo "morning"; } And {echo "afternoon or evening"; }? & Gt; The problem is that the value I received from the database is a formatted time format (eg: 2014-09-08 06: 00:00). I can format using this date:
$ time-> Format ('h'); To filter the date, month and date from year to year. But you can not use it as a variable, this is what I am trying to do:
Now I am not doing this because I am trying to use formatted date as a variable that does not work. Is there another way to turn off the day using the formatted date?
Regards, Mathematics
& lt ;? Php $ delivery time = new date time ('2014-09-08 06:00:00'); $ Hour = $ distribution-> Format ('h'); If ($ hour and lieutenant; 12) {echo "morning"; } And {echo "afternoon or evening"; }? & Gt; $ deliverytime-> Format () is a method that returns a formatted date and you have to store it somewhere to use that method, as the code above the show.
Similarly, if you are sending the whole object to an if statement, you should be the result of the method you use.
Comments
Post a Comment