Jump to content

Luggruff

New Members
  • Posts

    6
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Luggruff's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hmm, neat. It's still not fool proof though, because it doesn't account for days. 01:00:00 would be < 23:59:59, even though it could technically be after. Well I've found a way to account for the day, at least for what I need it for (just personal use, lots of code but little traffic) Solved! <td class=" <?php date_default_timezone_set('Europe/Stockholm'); $hour = date('H:i'); $day = date('D'); if ($hour > "22:00" && $hour < "23:50" && $day == "Mon") { echo "cell_is_gold"; } else { echo "cell_is_not_gold"; } ?> "> So, whenever it's Monday, and the time is between 22:00 and 23:50, that <td> cell is gonna get a nice little change of class. And whatever you say about how wrong it is, it is not, because it actually works like a charm for just that.
  2. On another note: Looks like it's gonna be a long night. Just realized I need to make sure it's the same weekday as too (say "if it's between 22:00 and 23:00 and today is tuesday, then class = "class1"). Any idea on how I should do that? Tried changing if ($hour > "22:00" && $hour < "23:50") To if ($hour > "22:00" && $hour < "23:50" && D == "Mon") and if ($hour > "22:00" && $hour < "23:50" && $D == "Mon") but seems to have no effect.. I don't think this is doing what you think it is. That comparison is going to be interpreted as a string, and you can't compare strings that way. Well, I have a table cell, see, and I want it to use a .css class that makes it all gold and shiny when the time is between 22:00 and 23:50, and when it's not in between those times, it will just be sad and gray. I tested it, and it worked. So I'm not really following you when you say that I can't do it, since I just did. So, you're really just saying that 23:00:00 is more than 22:59:59? Obviously it is. Why would I need to learn it from the start and completely, if I'm just making some tiny functions to supplement 99.999% HTML code a year? Using it as little as I am, I will remember as much of it when I need it as I do now when I need it and never knew it, if I ever learn it all.
  3. Thanks for the link, but still, that's what I've looked at for hours. Either I'm unable to get it or I've looked at it wrong for too long to get it. I've finally gotten something to work and it was less messy <?php date_default_timezone_set('Europe/Stockholm'); $hour = date('H:i'); if ($hour > "22:00" && $hour < "23:50") { echo "class1"; } else { echo "class2"; } ?> or a complete example (since you never find them when looking for them and someone might stumble upon this): <td class=" <?php date_default_timezone_set('Europe/Stockholm'); $hour = date('H:i'); if ($hour > "22:00" && $hour < "23:50") { echo "twobgcurrent"; } else { echo "twobg"; } ?> "></td> PHP does not recognize 20:00 as a value as you have it. Date/times can be represented as a timestamp (which is an integer that represents the number of seconds since Jan 1, 1970) or as a string, e.g. "20:00". But, string values cannot be compared using < or > like you want. You will need to implement some actual logic to do the check for you. EDIT: Your current comparisons look to be off. The first one checks for times before 8PM or after 1AM. But, the second is checking for times after 8PM or before 2PM. I did know that about Jan 1, 1970 actually.. still, saying that I need to implement logic is really unneccessary, as I already said that's what I'm struggling with -> To find logic. you mean 8PM or after 1AM, and the second one say 8PM or after 2AM, right? How do you figure it says 2PM?
  4. So I managed to print the time.. <?php putenv("TZ=Europe/Stockholm"); $t=time(); echo(date("H i",$t)); ?> ..still though, been trying for two hours to use this in my favour, but with no luck Keep getting errors like "unexpected T_AND_EQUAL" and "unexpected T_GREATER_OR_EQUAL". Guess I'm just too dumb..
  5. Pretty much not at all (displayed). And maybe I could be more specific as to what I've tried... When using this code <?php if ($time<20:00&>1:00) { echo "class1";} else if($time>20:00&<2:00) { echo "class2";}?> I get the response "Parse error: syntax error, unexpected ':' in /hermes/....php on line 180" So I tried changing it to <?php if ($hhmm<2000&>0100) { echo "class1";} else if($hhmm>2000&<0200) { echo "class2";}?> and I get the response "Parse error: syntax error, unexpected '<' in /hermes/....php on line 180" (also with $time, so i tried $hhmm instead wich made no diff.) So I tried changing it to <?php if ($hhmm<=2000&=>0100) { echo "class1";} else if($hhmm=>2000&<=0200) { echo "class2";}?> and I get the response "Parse error: syntax error, unexpected T_AND_EQUAL in /hermes/.....php on line 180" I don't know enough php to check what's wrong or not, since I don't know the language as of yet more than enough to be able to sometimes use snippets of code for specific functions.
  6. Been googling this for hours now and I can't find something that doesn't give a parse error. I found this thread: http://www.phpfreaks.com/forums/index.php?topic=160855 ..and tried to work around the answer but with no luck. All I really want to do is something like this: <td class=" <?php if ($time<20:00&>1:00) { echo "class1";} else if($time>20:00&<2:00) { echo "class2";}?> "></td> I want the class to change to another one if the user see the table cell within a specific hour of the day.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.