Calculating tim - easy for you! =)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • georgios zakitraxis

    Calculating tim - easy for you! =)

    Hello out there in the jungle...
    =)

    I found out that i can calculate the dates e.g

    $today = strftime('%Y%m% d',mktime(0, 0, 0, date("m"), date("d"),
    date("Y")));
    $yesterday = strftime('%Y%m% d',mktime(0, 0, 0, date("m"), date("d") - 1,
    date("Y")));
    $dayBeforeYeste rday = strftime('%Y%m% d',mktime(0, 0, 0, date("m"),
    date("d") - 2, date("Y")));
    $dayBeforeTheDa yBeforeYesterda y = strftime('%Y%m% d',mktime(0, 0, 0,
    date("m"), date("d") - 2, date("Y")));

    and so on........

    This works even if we have the 1st of August $yesterday gives me the 31st
    july.

    Can I do this with times also??

    e.g. Iit it now 17:06 an i want to make minus 20 min (like abopve minus 1
    day) and I want the result to be 16:46.
    I tried the above example, wit %H%M but it does not work?

    Any ideas?

    Thanks

    :-X
  • Tim Van Wassenhove

    #2
    Re: Calculating tim - easy for you! =)

    In article <8c590c7e.04071 00716.3eaa6fba@ posting.google. com>, georgios zakitraxis wrote:[color=blue]
    > Hello out there in the jungle...
    >=)
    >
    > I found out that i can calculate the dates e.g[/color]

    My favorite function: strtotime

    Check it out in the manual :)


    --
    Tim Van Wassenhove <http://home.mysth.be/~timvw>

    Comment

    • Pedro Graca

      #3
      Re: Calculating tim - easy for you! =)

      georgios zakitraxis wrote:[color=blue]
      > Can I do this with times also??[/color]
      ....[color=blue]
      > I tried the above example, wit %H%M but it does not work?[/color]

      Yes, it does :)

      $a_little_while _ago = strftime('%Y%m% d %H%M', mktime(date('H' ),
      date('i')-20, date('s'), date('m'), date('d'), date('y')));


      --
      USENET would be a better place if everybody read: | to email me: use |
      http://www.catb.org/~esr/faqs/smart-questions.html | my name in "To:" |
      http://www.netmeister.org/news/learn2quote2.html | header, textonly |
      http://www.expita.com/nomime.html | no attachments. |

      Comment

      • Chung Leong

        #4
        Re: Calculating tim - easy for you! =)

        "georgios zakitraxis" <efzoni@yahoo.d e> wrote in message
        news:8c590c7e.0 407100716.3eaa6 fba@posting.goo gle.com...[color=blue]
        > Hello out there in the jungle...
        > =)
        >
        > I found out that i can calculate the dates e.g
        >
        > $today = strftime('%Y%m% d',mktime(0, 0, 0, date("m"), date("d"),
        > date("Y")));
        > $yesterday = strftime('%Y%m% d',mktime(0, 0, 0, date("m"), date("d") - 1,
        > date("Y")));
        > $dayBeforeYeste rday = strftime('%Y%m% d',mktime(0, 0, 0, date("m"),
        > date("d") - 2, date("Y")));
        > $dayBeforeTheDa yBeforeYesterda y = strftime('%Y%m% d',mktime(0, 0, 0,
        > date("m"), date("d") - 2, date("Y")));
        >
        > and so on........[/color]

        Unix timestamps are in general easier to work with as they're just numbers:

        define(SECONDS_ IN_A_DAY, 60 * 60 * 24);

        $now = time();
        $today = date("Y m d", $now);
        $yesterday = date("Y m d", $now - SECONDS_IN_A_DA Y);
        $dayBeforeYeste rday = date("Y m d", $now - SECONDS_IN_A_DA Y * 2);
        $dayBeforeTheDa yBeforeYesterda y = date("Y m d", $now - SECONDS_IN_A_DA Y *
        3);


        Comment

        Working...