Welcome Guest, Not a member yet? Register   Sign In
What time is it Mr Wolf? Issues with timespan :D
#1

[eluser]CI Lee[/eluser]
Hello All,

I was trying to find an answer to another problem, simple and in hindsight very easy; however no matter how I phrased it I could not find any topics that referenced it. So I had to ask in a post...

This may seem simple to some but I am sure it may help others in the future and by bolstering the search results, reducing the novice questions.

I am building a CMS and I would like to alert the user when something has reached a threshold in time. Now its rudimentary but it works... kinda(get to that in a second) this is what I have
Code:
<div id="date" style="float:right; width:90%" >
                <p>&lt;? if ( $row->date <= strtotime("-30 days") ) { ?&gt;
                    <span style="color:red">
            &lt;? }
                else { ?&gt;
                    <span>
            &lt;?    } ?&gt; &lt;?=timespan($row->date)?&gt; ago</p>
            </div>&lt;!-- /date --&gt;

Great now that I have figured that part out lets make some post...

Wait a minute, kept saying "1 second ago" even though it was posted one minute ago...

So I went through my checklist and confirmed that the date was indeed being passed from as a unix time format, the date is being inserted into the database correctly... then I found it!

The posts have somehow generated 1.21 Gigawatts of power and hit 88 mph.. my post is in the future.

So the post was saying "1 second ago" because the date has not become a date in the past yet, even though it has passed... yeah too late for things like that. Turns out it was an issue with the local dev server, live server it runs fine.


-Lee




Theme © iAndrew 2016 - Forum software by © MyBB