managing date

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

    managing date

    Hi,

    I've got a string that contains a date with the following format :
    yyyy-mm-dd hh:mm:ss
    ex :
    2003-10-10 11:37:47

    I'd like to get 4 variables :
    - 1 for the year number,
    - 1 for the month,
    - 1 for the day,
    - 1 for the time.

    How is it possible ?
    Must I use the explode function or is there another way ?

    many thanks in advance,
    cheers,
    --
    nyso


  • The Biscuit Eater

    #2
    Re: managing date


    "nyso" <nyso@no-spam.org> wrote in message
    news:3fa0cf12$0 $27566$626a54ce @news.free.fr.. .[color=blue]
    > Hi,
    >
    > I've got a string that contains a date with the following format :
    > yyyy-mm-dd hh:mm:ss
    > ex :
    > 2003-10-10 11:37:47
    >
    > I'd like to get 4 variables :
    > - 1 for the year number,
    > - 1 for the month,
    > - 1 for the day,
    > - 1 for the time.
    >
    > How is it possible ?
    > Must I use the explode function or is there another way ?[/color]


    I did something like this (but not with the time) and posted an example
    recently. I am new to this, but you could explode on the space and you would
    have date and time, then explode on the date and get the year, month and
    day.

    Bill


    Comment

    • nyso

      #3
      Re: managing date

      > I did something like this (but not with the time) and posted an example[color=blue]
      > recently. I am new to this, but you could explode on the space and you[/color]
      would[color=blue]
      > have date and time, then explode on the date and get the year, month and
      > day.
      >
      > Bill[/color]

      That's what I'm doing at the moment... but it doesn't seem "clean" to me.
      I'm searching for a better solution.

      --
      nyso


      Comment

      • Clubberboy

        #4
        Re: managing date

        Op Thu, 30 Oct 2003 09:43:15 +0100 schreef "nyso" <nyso@no-spam.org>:
        [color=blue]
        >I've got a string that contains a date with the following format :
        >yyyy-mm-dd hh:mm:ss
        >ex :
        >2003-10-10 11:37:47
        >
        >I'd like to get 4 variables :
        >- 1 for the year number,
        >- 1 for the month,
        >- 1 for the day,
        >- 1 for the time.
        >
        >How is it possible ?
        >Must I use the explode function or is there another way ?[/color]

        Try this:

        $date_time="200 3-10-15 11:37:47";

        $year=strftime( "%Y",strtotime( $date_time));
        $month=strftime ("%m",strtotime ($date_time));
        $day=strftime(" %d",strtotime($ date_time));
        $time=strftime( "%H:%M:%S",strt otime($date_tim e));


        --
        Ontvang hoogwaardig IT-consultancy en maatwerksoftwareoplossingen, professionele smart contract-audits en blockchain-advies, en boeiende e-learning-cursussen. Onze expertise omvat een breed scala aan diensten die uw bedrijf naar de volgende digitale fase leiden. Neem vandaag nog contact met ons op en ontdek hoe wij u kunnen helpen uw technologische doelen te bereiken

        Comment

        • Alvaro G Vicario

          #5
          Re: managing date

          *** nyso wrote/escribió (Thu, 30 Oct 2003 09:43:15 +0100):[color=blue]
          > 2003-10-10 11:37:47
          >
          > I'd like to get 4 variables :
          > - 1 for the year number,
          > - 1 for the month,
          > - 1 for the day,
          > - 1 for the time.[/color]

          <?php
          if (ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $date, $regs)) {
          echo "$regs[3].$regs[2].$regs[1]";
          } else {
          echo "Invalid date format: $date";
          }
          ?>

          I hope this helps. It's taken from ereg() reference.


          --
          --
          -- Álvaro G. Vicario - Burgos, Spain
          --

          Comment

          • R. Rajesh Jeba Anbiah

            #6
            Re: managing date

            "nyso" <nyso@no-spam.org> wrote in message news:<3fa0cf12$ 0$27566$626a54c e@news.free.fr> ...[color=blue]
            > Hi,
            >
            > I've got a string that contains a date with the following format :
            > yyyy-mm-dd hh:mm:ss
            > ex :
            > 2003-10-10 11:37:47
            >
            > I'd like to get 4 variables :
            > - 1 for the year number,
            > - 1 for the month,
            > - 1 for the day,
            > - 1 for the time.
            >
            > How is it possible ?
            > Must I use the explode function or is there another way ?[/color]

            You may use:

            $date_str = "2003-10-10 11:37:47";
            list($y, $m, $d, $hh, $mm, $ss) = sscanf($date_st r,"%4d-%2d-%2d
            %2d:%2d:%2d");
            echo $y;
            echo $m;
            .....

            ---
            "He who created the god was a fool; he who spreads his name is a
            scoundrel and he who worships him is a barbarian."---Periyar, Famous
            Tamil Rationalist
            Email: rrjanbiah-at-Y!com

            Comment

            • Pat Scott

              #7
              Re: managing date

              $datearr = split("[- ]",$bigfield );

              $datearr[0] will contain the year
              $datearr[1] will contain the month
              $datearr[2] will contain the day
              $datearr[3] will contain the time

              "R. Rajesh Jeba Anbiah" <ng4rrjanbiah@r ediffmail.com> wrote in message
              news:abc4d8b8.0 311010458.44652 889@posting.goo gle.com...[color=blue]
              > "nyso" <nyso@no-spam.org> wrote in message[/color]
              news:<3fa0cf12$ 0$27566$626a54c e@news.free.fr> ...[color=blue][color=green]
              > > Hi,
              > >
              > > I've got a string that contains a date with the following format :
              > > yyyy-mm-dd hh:mm:ss
              > > ex :
              > > 2003-10-10 11:37:47
              > >
              > > I'd like to get 4 variables :
              > > - 1 for the year number,
              > > - 1 for the month,
              > > - 1 for the day,
              > > - 1 for the time.
              > >
              > > How is it possible ?
              > > Must I use the explode function or is there another way ?[/color]
              >
              > You may use:
              >
              > $date_str = "2003-10-10 11:37:47";
              > list($y, $m, $d, $hh, $mm, $ss) = sscanf($date_st r,"%4d-%2d-%2d
              > %2d:%2d:%2d");
              > echo $y;
              > echo $m;
              > .....
              >
              > ---
              > "He who created the god was a fool; he who spreads his name is a
              > scoundrel and he who worships him is a barbarian."---Periyar, Famous
              > Tamil Rationalist
              > Email: rrjanbiah-at-Y!com[/color]


              Comment

              • nyso

                #8
                Re: managing date

                "Pat Scott" <jscott4272@com cast.net> a écrit dans le message de news:
                EKKdnSitnZjTLD6 iRVn-hg@comcast.com...[color=blue]
                > $datearr = split("[- ]",$bigfield );
                >
                > $datearr[0] will contain the year
                > $datearr[1] will contain the month
                > $datearr[2] will contain the day
                > $datearr[3] will contain the time
                >
                > "R. Rajesh Jeba Anbiah" <ng4rrjanbiah@r ediffmail.com> wrote in message
                > news:abc4d8b8.0 311010458.44652 889@posting.goo gle.com...[/color]

                thank you very much for your help.
                this was very useful for me.

                thanks again,
                --
                nyso


                Comment

                Working...