Adding 1 second to a timestamp while looping

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

    Adding 1 second to a timestamp while looping

    Hi there,
    I'm trying to add 1 second incrementally to a timestamp while looping
    through it and I am pulling my hair out.

    Please can someone help me?

    example of code:

    $calc_timestamp =
    date('YmdHis',m ktime(date('H') ,date('i'),date ('s')-50,date('m'),da te('d'),date('Y ')));

    This gets the timestamp to be 50 seconds before the time now.

    I want to loop through the 50 itmes and add them to a table, but
    incremntally increase the timestamp by 1 second and then post it to the
    table so that the final item will have the timestamp as at the time of
    posting the information

    Please help!

    Andrew


  • Sathia Musso

    #2
    Re: Adding 1 second to a timestamp while looping

    $calc_timestamp ++;

    --[color=blue][color=green]
    >> man man ; man cd; man ls; man bash[/color]
    > fatto non succede nulla[/color]

    Comment

    • Sathia Musso

      #3
      Re: Adding 1 second to a timestamp while looping

      Sathia Musso wrote:
      [color=blue]
      > $calc_timestamp ++;
      >[/color]


      i'm sorry, i use linux_timestamp (epoch) and i wrote something wrog indeed.



      --[color=blue][color=green]
      >> man man ; man cd; man ls; man bash[/color]
      > fatto non succede nulla[/color]

      Comment

      • Geoff Berrow

        #4
        Re: Adding 1 second to a timestamp while looping

        I noticed that Message-ID: <cs3cj5$2th$1@c tb-nnrp2.saix.net> from Stegga
        contained the following:
        [color=blue]
        >I want to loop through the 50 itmes and add them to a table, but
        >incremntally increase the timestamp by 1 second and then post it to the
        >table so that the final item will have the timestamp as at the time of
        >posting the information
        >
        >Please help![/color]

        $now=strtotime( "now");
        for($i=50;$i>0; $i--){
        $calc_timestamp =
        date('YmdHis',m ktime(date('H') ,date('i'),date ('s',$now)-$i,date('m'),da te('d'),date('Y ')));
        print "$calc_timestam p<br>";
        }

        --
        Geoff Berrow (put thecat out to email)
        It's only Usenet, no one dies.
        My opinions, not the committee's, mine.
        Simple RFDs http://www.ckdog.co.uk/rfdmaker/

        Comment

        • Geoff Berrow

          #5
          Re: Adding 1 second to a timestamp while looping

          I noticed that Message-ID: <sreau05jlpn326 mvrbvjc8mcvh31i ok9f6@4ax.com>
          from Geoff Berrow contained the following:
          [color=blue]
          >$now=strtotime ("now");
          >for($i=50;$i>0 ;$i--){
          >$calc_timestam p =
          >date('YmdHis', mktime(date('H' ),date('i'),dat e('s',$now)-$i,date('m'),da te('d'),date('Y ')));
          >print "$calc_timestam p<br>";
          >}[/color]

          oops, make that
          for($i=50;$i>-1;$i--){
          --
          Geoff Berrow (put thecat out to email)
          It's only Usenet, no one dies.
          My opinions, not the committee's, mine.
          Simple RFDs http://www.ckdog.co.uk/rfdmaker/

          Comment

          • porneL

            #6
            Re: Adding 1 second to a timestamp while looping

            >> $now=strtotime( "now");

            why not simply $now = time();?
            [color=blue][color=green]
            >> date('YmdHis',m ktime(date('H') ,date('i'),date ('s',$now)-$i,date('m'),da te('d'),date('Y ')));[/color][/color]

            why not simply date('YmdHis',$ now--);?


            --
            * html {redirect-to: url(http://browsehappy.pl) ;}

            Comment

            • Alvaro G Vicario

              #7
              Re: Adding 1 second to a timestamp while looping

              *** Stegga wrote/escribió (Wed, 12 Jan 2005 16:35:12 +0200):[color=blue]
              > $calc_timestamp =
              > date('YmdHis',m ktime(date('H') ,date('i'),date ('s')-50,date('m'),da te('d'),date('Y ')));[/color]
              [color=blue]
              > This gets the timestamp to be 50 seconds before the time now.[/color]

              $calc_timestamp =time()-50;
              while(...){
              $calc_timestamp ++;
              ...
              }



              --
              -- Álvaro G. Vicario - Burgos, Spain
              -- Thank you for not e-mailing me your questions
              --

              Comment

              • Geoff Berrow

                #8
                Re: Adding 1 second to a timestamp while looping

                I noticed that Message-ID: <opskhxb9szkzdn 26@localhost> from porneL
                contained the following:
                [color=blue]
                >why not simply $now = time();?
                >[color=green][color=darkred]
                >>> date('YmdHis',m ktime(date('H') ,date('i'),date ('s',$now)-$i,date('m'),da te('d'),date('Y ')));[/color][/color]
                >
                >why not simply date('YmdHis',$ now--);?[/color]

                Um..I was in a hurry?

                Yes, that's much neater

                <?
                $now=time();
                for($i=50;$i>-1;$i--){
                $calc_timestamp =
                date('YmdHis',$ now--);
                print "$calc_timestam p<br>";
                }
                ?>

                --
                Geoff Berrow (put thecat out to email)
                It's only Usenet, no one dies.
                My opinions, not the committee's, mine.
                Simple RFDs http://www.ckdog.co.uk/rfdmaker/

                Comment

                Working...