Jump to content

Archived

This topic is now archived and is closed to further replies.

mikeroq

Today and Yesterday

Recommended Posts

Im trying to make a today and yesterday function for unix time stamps, i did one but i made it very wrong, it works, it just doesnt work right.

I though of taking off 84600 or 86400 w/e it is, but then that presents a problem cause then it would be a rolling date, i need a function that will do this.


Thanks

Share this post


Link to post
Share on other sites
You might want to look at the strtotime() function:
[code]<?php
$today = strtotime('today');
$yesterday = strtotime('yesterday');
echo '$today = ' . $today . '<br>$yesterday = ' . $yesterday;
?>[/code]

Ken

Share this post


Link to post
Share on other sites
ok this no longer works, this is my code
[code]
function nixtime($unix)
    {  
        if ($unix == "1129679173")
            {
                return "Never";
            }
        else {
        $unix = $unix;
          $today = strtotime("today");
        $yesterday = strtotime("yesterday");
        $two = strtotime("2 days ago");
        if ($unix < $today && $unix > $yesterday)
        {          
        $visit = date('g:i a', $unix );
        return "Today, $visit";
        }
        if ($unix > $two && $unix < $yesterday)
        {          
        $visit = date('g:i a', $unix );
        return "Yesterday, $visit";
        }
        else {        
        $visit = date('n/j/y g:i a', $unix );
        return $visit;
        }
           }
      }
[/code]

[a href=\"http://mikeroq.be/?x=forum\" target=\"_blank\"]http://mikeroq.be/?x=forum[/a]

or anywhere else, it willl say yesterday for today, and today for yesterday and show incorrect times like today at 6:30am when its only 4:30am server time

Share this post


Link to post
Share on other sites
You are defining today as any time in the last 24 hours and not as times since midnight.

Try
[code]function nixtime($unix)
    {
        if ($unix == "1129679173")
            {
                return "Never";
            }
        else {
            $today = mktime(0,0,0, date('m'), date('d'), date('Y'));
            $yesterday = mktime(0,0,0, date('m'), date('d')-1, date('Y'));

            if ($unix > $today)
                {
                $visit = date('g:i a', $unix );
                return "Today, $visit";
                }
            elseif ($unix > $yesterday && $unix < $today)
                {
                $visit = date('g:i a', $unix );
                return "Yesterday, $visit";
                }
            else {
                $visit = date('n/j/y g:i a', $unix );
                return $visit;
            }
        }
    }[/code]

Share this post


Link to post
Share on other sites

×

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.