0

My apologies for not knowing how to do this, but it seems like it should be simple. I am trying to use PHP to hide certain events on a calendar that are being imported with an incorrect timestamp (2:00 AM should be All Day).

This is what I'm trying to use, but it is not working.

Any help would be greatly appreciated.

<?php
$t = field_event_date;

if ($t ="2:00 AM") {
  echo "All Day";
}
?>
TomG
  • 1
  • 1
  • 2
    "*it is not working.*" *How* is it not working? Are you aware that `=` is *assignment*, and is materially different than `==` or `===` used for comparison? What data does `field_event_date` hold, and are you sure it's in the form of `h:mm aa`? – esqew Feb 07 '22 at 14:53
  • What is `field_event_date`? A lower case constant? Should it be a variable (it' should then be `$field_event_date`) or a function call (it should then be `field_event_date()`) or something else? – M. Eriksson Feb 07 '22 at 14:57
  • @esqew - I honestly don't know how to write PHP so that is a large part of the problem. I can see that field_event_date_2 returns the 02:00 AM time by using a piece of code that displays All Day based on the criteria, but doesn't replace/hide the original 02:00 AM time (both are displayed). I don't know the difference between = or == ===, but the time is being stored as 02:00 AM . – TomG Feb 07 '22 at 15:11
  • `=` is assignment, `==` is comparison and `===` is strict comparison. Your `if()` statement is always going to be `true`, since you only used `=`, which is assignment, and in your case, won't likely "fail" for any reason. – Tim Lewis Feb 07 '22 at 15:14
  • @M.Eriksson - field_event_date_2 is a display for the time of the event that is going to occur. I don't know how to write PHP so whether it is a variable or a function call I cannot answer. I can put a piece of PHP on the View so that it changes any time that is 02:00 AM to All Day, but it isn't working. Again, sorry for being unfamiliar with PHP. I believe it will work in this instance, but am unsure of how to write it. Thanks. – TomG Feb 07 '22 at 15:14
  • But where does it come from? "is a display for the time" isn't a useful answer. To be honest, if you don't know PHP well enough to answer if the code you've posted really should be a variable, function or a constant (or the difference between `=`, `==` and `===`), you need to read through some PHP 101 guides to learn the basics first. If you don't know them, then I don't see how we would be able to help either, since you won't be able to do basic basic debugging to narrow the issue down. We're glad to help, but we can't teach you all the basics and won't write your code for you. – M. Eriksson Feb 07 '22 at 15:25
  • @M.Eriksson - Thanks, but apparently I am out of my league here. Thought I could get some help. – TomG Feb 07 '22 at 15:34

1 Answers1

0
if ($t == "2:00 AM") {
  echo "All Day";
}

you have an error in if condition

Aurang Zeb
  • 11
  • 2