Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #17598

Re: Days until Christmas

From "Christoph M. Becker" <cmbecker69@arcor.de>
Newsgroups comp.lang.php
Subject Re: Days until Christmas
Date 2017-10-27 01:38 +0200
Organization solani.org
Message-ID <ostrlr$6i5$1@solani.org> (permalink)
References (3 earlier) <gLOHB.37370$Ov1.6569@fx30.iad> <59f1b002$0$818$e4fe514c@news.xs4all.nl> <7zoIB.22653$463.8426@fx13.iad> <ost629$o1b$1@solani.org> <6KtIB.155563$J83.116459@fx06.iad>

Show all headers | View raw


On 27.10.2017 at 00:56, Mark Lloyd wrote:

> On 10/26/2017 12:29 PM, Christoph M. Becker wrote:
>
>> Wouldn't
>>
>>    (new DateTime('now'))
>>      ->diff(new DateTime('2017-12-25T00:00'))
>>      ->format('%a days until Christmas')
>>
>> suffice?  Okay, that rounds down, and your solution rounds up, but that
>> could be catered to.
> 
> I've tried this and it seems to be working OK. I may be able to use it
> except I prefer a result that is more precise than days.
> 
> One odd thing is that when I looked at the PHP documentation for
> DateTime -> format, it says it uses the same parameters as the "date"
> function, these DO NOT use % signs. 'a' itself shows am or pm. Where did
> you get %a for DateTime -> format?

DateTime::diff(DateTime) returns a DateInterval (not a DateTime) object,
and its ::format() method expects a somewhat different format[1].  If
you want more detailed information, you can use something like this:

 ->format('%a days, %h hours, %i minutes and %s seconds …')

[1] <http://www.php.net/manual/en/dateinterval.format.php>

-- 
Christoph M. Becker

Back to comp.lang.php | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

its quiet here - test bill <william@TechServSys.com> - 2017-10-22 07:58 -0400
  Re: its quiet here - test hah <hah@no.email.stupid.invalid> - 2017-10-22 15:31 -0500
    Re: its quiet here - test Luuk <luuk@invalid.lan> - 2017-10-24 10:12 +0200
      Re: its quiet here - test Mark Lloyd <not@mail.invalid> - 2017-10-24 17:01 -0500
        Re: its quiet here - test Luuk <luuk@invalid.lan> - 2017-10-26 11:51 +0200
          Re: its quiet here - test Mark Lloyd <not@mail.invalid> - 2017-10-26 12:02 -0500
            Days until Christmas (was: its quiet here - test) "Christoph M. Becker" <cmbecker69@arcor.de> - 2017-10-26 19:29 +0200
              Re: Days until Christmas Mark Lloyd <not@mail.invalid> - 2017-10-26 17:56 -0500
                Re: Days until Christmas "Christoph M. Becker" <cmbecker69@arcor.de> - 2017-10-27 01:38 +0200
                Re: Days until Christmas Mark Lloyd <not@mail.invalid> - 2017-10-26 20:48 -0500

csiph-web