oz11 Posted September 12, 2023 Share Posted September 12, 2023 (edited) I wrote this.. $now = strtotime('now'); $now = date('Y-m-d', $now); $day = date('Y-m-d', strtotime($row['date'] . ' + 2 weeks')); if($day < $now){ echo "<img src='https://i.imgur.com/0rlIlUD.gif'>"; } It should show a "new" gif image on new posts.. however, they only show on posts that are not new. I tried flipping the "<" to ">" but doesn't work.... not sure what to do. So simple but get can't grasp the conditional . Help Internet freaks. Edited September 12, 2023 by oz11 Quote Link to comment https://forums.phpfreaks.com/topic/317280-new-posts/ Share on other sites More sharing options...
Barand Posted September 12, 2023 Share Posted September 12, 2023 What value does $row['date'] contain? Quote Link to comment https://forums.phpfreaks.com/topic/317280-new-posts/#findComment-1611789 Share on other sites More sharing options...
oz11 Posted September 12, 2023 Author Share Posted September 12, 2023 (edited) The date of the post, eg (a real example) of "2022-11-22"  update : "2022-11-22 16:03:32" not just "2022-11-22" Edited September 12, 2023 by oz11 fix Quote Link to comment https://forums.phpfreaks.com/topic/317280-new-posts/#findComment-1611790 Share on other sites More sharing options...
oz11 Posted September 12, 2023 Author Share Posted September 12, 2023 oops. its abit longer "2022-11-22 16:03:32" (take two) Quote Link to comment https://forums.phpfreaks.com/topic/317280-new-posts/#findComment-1611791 Share on other sites More sharing options...
oz11 Posted September 12, 2023 Author Share Posted September 12, 2023 (edited) Still not fixed it . You would think flipping it would work as it sorta did before, but opposite. all t he ones that shouldn't be "new" were new and all the other actual "new" posts were not showing.. weird. Never come across anything like it. Edited September 12, 2023 by oz11 Quote Link to comment https://forums.phpfreaks.com/topic/317280-new-posts/#findComment-1611792 Share on other sites More sharing options...
Barand Posted September 12, 2023 Share Posted September 12, 2023 This works for me (if I substitute a datetime value over 2 weeks old for $row['date'] ) $day = date('Y-m-d', strtotime("2023-08-28 16:03:32" . ' + 2 weeks')); if ($day < date('Y-m-d')) { echo "img src='https://i.imgur.com/0rlIlUD.gif'"; }  Quote Link to comment https://forums.phpfreaks.com/topic/317280-new-posts/#findComment-1611793 Share on other sites More sharing options...
requinix Posted September 12, 2023 Share Posted September 12, 2023 5 minutes ago, Barand said: This works for me (if I substitute a datetime value over 2 weeks old for $row['date'] ) "Works" in that it outputs this image: ... Quote Link to comment https://forums.phpfreaks.com/topic/317280-new-posts/#findComment-1611794 Share on other sites More sharing options...
oz11 Posted September 12, 2023 Author Share Posted September 12, 2023 (edited) 12 minutes ago, Barand said: This works for me (if I substitute a datetime value over 2 weeks old for $row['date'] ) $day = date('Y-m-d', strtotime("2023-08-28 16:03:32" . ' + 2 weeks')); if ($day < date('Y-m-d')) { echo "img src='https://i.imgur.com/0rlIlUD.gif'"; }  Still shows on the reverse but not the other way round hmm. (showing on all the old ones but not the new ones) Edited September 12, 2023 by oz11 Quote Link to comment https://forums.phpfreaks.com/topic/317280-new-posts/#findComment-1611795 Share on other sites More sharing options...
Solution Barand Posted September 12, 2023 Solution Share Posted September 12, 2023 59 minutes ago, oz11 said: It should show a "new" gif image on new posts Do I take it that a new image is one that is less than 2 weeks old? $day = date('Y-m-d', strtotime("2023-08-30 16:03:32")); if($day > date('Y-m-d', strtotime('-2 weeks'))){ echo "img src='https://i.imgur.com/0rlIlUD.gif'"; } @requinix - I see what you mean 1 Quote Link to comment https://forums.phpfreaks.com/topic/317280-new-posts/#findComment-1611796 Share on other sites More sharing options...
oz11 Posted September 13, 2023 Author Share Posted September 13, 2023 (edited) Ended up doing this which worked... Â //$day = date('Y-m-d', $row['date']); $day = date('Y-m-d', strtotime($row['date'])); if($day < date('Y-m-d', strtotime('-2 weeks'))){ } ELSE { echo "<img src='ttps://i.imgur.com/0rlIlUD.gif'>"; } abit of a workaround but ok for me. Thanks guys! Edited September 13, 2023 by oz11 Quote Link to comment https://forums.phpfreaks.com/topic/317280-new-posts/#findComment-1611821 Share on other sites More sharing options...
requinix Posted September 13, 2023 Share Posted September 13, 2023 That's the same thing as Barand posted, except you flipped the condition which then forced you to use that else block. Quote Link to comment https://forums.phpfreaks.com/topic/317280-new-posts/#findComment-1611828 Share on other sites More sharing options...
oz11 Posted September 13, 2023 Author Share Posted September 13, 2023 6 minutes ago, requinix said: That's the same thing as Barand posted, except you flipped the condition which then forced you to use that else block. Ooops. Fixed .,Thanks guys again! Quote Link to comment https://forums.phpfreaks.com/topic/317280-new-posts/#findComment-1611829 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.