Re: Date formatting issue

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Aug 5, 2008 at 11:48 AM, Don Don <progwihz@xxxxxxxxx> wrote:
> Hi all,
>
> I've got dates in the following formats e.g.
>
> August 05, 2008, 10:14 am (e.g. today's date)
> August 04, 2008, 7:08 am (e.g. yesterda's date)
> August 03, 2008, 9:08 am (e.g. in the past)
>
> I am trying to format these dates do I can display them like this
>
> Today at 10:14 am (today)
> Yesterday at 9:08 am (yesterday)
> August 03, 9:08 am (if its not today or yesterday then display the month and day and time only)

    If $month equals date("m") and $year equals date("Y") and $day
equals date("d") - 1 then it's yesterday.

    If $month equals date("m") and $year equals date("Y") and $day
equals date("d") then it's today.

    If $month equals date("m") and $year equals date("Y") and $day
equals date("d") + 1 then it's tomorrow.

    Otherwise, echo date("F d, g:i a");


    As Dan Joseph mentioned, read up on date()[1] and mktime()[2], and
I'd also recommend strtotime()[3].  Moreover, take the logic above and
code your PHP to match it. A simple if/elseif/else or case/switch
block will do it for you.



        1:  http://php.net/date
        2:  http://php.net/mktime
        3:  http://php.net/strtotime

-- 
</Daniel P. Brown>
More full-root dedicated server packages:
Intel 2.4GHz/60GB/512MB/2TB $49.99/mo.
Intel 3.06GHz/80GB/1GB/2TB $59.99/mo.
Intel 2.4GHz/320/GB/1GB/3TB $74.99/mo.
Dedicated servers, VPS, and hosting from $2.50/mo.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux