Jump to content


Photo

Today and Yesterday


  • Please log in to reply
4 replies to this topic

#1 mikeroq

mikeroq
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 18 March 2006 - 01:42 AM

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

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 18 March 2006 - 02:28 AM

You might want to look at the strtotime() function:
<?php
$today = strtotime('today');
$yesterday = strtotime('yesterday');
echo '$today = ' . $today . '<br>$yesterday = ' . $yesterday;
?>

Ken

#3 mikeroq

mikeroq
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 18 March 2006 - 08:28 AM

Thank you!

#4 mikeroq

mikeroq
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 26 March 2006 - 10:00 AM

ok this no longer works, this is my 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;
        }
           }
      }

[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

#5 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 26 March 2006 - 11:05 AM

You are defining today as any time in the last 24 hours and not as times since midnight.

Try
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;
            }
        }
    }

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users