still having problems with dates

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

    still having problems with dates

    Hi

    I am niew to pho and am having trouble with dates.

    I can format a date ok
    so $today=date('d M Y' )
    gives me 2 Nov 2005


    $dateval is a mysql date
    yyyy-mm-dd hh:nn:sss (2005-10-26 13:32:09)
    $today=date('d M Y' ,$dateval)
    gives me something like 1 july 1970

    I am not sure how to tell the php that the date is a date.

    It is driving me nuts, and the only particulary
    obscure thing I have encountered so far.

    i would be grateful for some advice

    thanks

    jonathan







    ===============
    Jonathan Crawford
    jc@tgsi.net
    ===============


  • Peter van Schie

    #2
    Re: still having problems with dates

    Jonathan Crawford wrote:[color=blue]
    > I am niew to pho and am having trouble with dates.
    >
    > I can format a date ok
    > so $today=date('d M Y' )
    > gives me 2 Nov 2005
    >
    >
    > $dateval is a mysql date
    > yyyy-mm-dd hh:nn:sss (2005-10-26 13:32:09)
    > $today=date('d M Y' ,$dateval)
    > gives me something like 1 july 1970[/color]

    Hi Jonathan,

    Try:

    $today=date('d M Y', strtotime($date val));

    HTH.
    Peter.

    --

    Comment

    • Erwin Moller

      #3
      Re: still having problems with dates

      Jonathan Crawford wrote:
      [color=blue]
      > Hi
      >
      > I am niew to pho and am having trouble with dates.[/color]

      Read the manual. :-)
      Really, it is the only things that helps.
      PHP is a popular general-purpose scripting language that powers everything from your blog to the most popular websites in the world.

      [color=blue]
      >
      > I can format a date ok
      > so $today=date('d M Y' )
      > gives me 2 Nov 2005[/color]

      which is fine.
      Except for the fact it is 4 november over here, is your time ok?
      [color=blue]
      >
      >
      > $dateval is a mysql date
      > yyyy-mm-dd hh:nn:sss (2005-10-26 13:32:09)
      > $today=date('d M Y' ,$dateval)[/color]

      And here you go wrong.

      Did you read what date() does in PHP?
      Check the manual: It says:

      -----------------------------------------
      Description
      string date ( string format [, int timestamp] )
      Returns a string formatted according to the given format string using the
      given integer timestamp or the current local time if no timestamp is given.
      In other words, timestamp is optional and defaults to the value of time().

      Note: To generate a timestamp from a string representation of the date, you
      may be able to use strtotime(). Additionally, some databases have functions
      to convert their date formats into timestamps (such as MySQL's
      UNIX_TIMESTAMP function).

      -----------------------------------------

      So.....

      What you should do is:
      1) read the manual
      2) make sure you know how your date is represented in mySQL, and how PHP
      wants it. Have a look at strtotime() and the like for help.

      In general: if a function is not behaving as expected, read the manual and
      see what is says.
      On www.php.net: if you cannot find your problem/answer, be sure to read the
      visitorscomment s too, they often contain usefull information.
      [color=blue]
      > gives me something like 1 july 1970
      >
      > I am not sure how to tell the php that the date is a date.
      >
      > It is driving me nuts, and the only particulary
      > obscure thing I have encountered so far.[/color]

      rtfm.
      [color=blue]
      >
      > i would be grateful for some advice
      >
      > thanks
      >
      > jonathan
      >[/color]

      Good luck!

      Regards,
      Erwin Moller

      Comment

      • Jonathan Crawford

        #4
        Re: still having problems with dates

        thanks ever so much,
        that was just what I needed and it does
        make sense to me now.

        thanks

        jc

        --
        ===============
        Jonathan Crawford
        jc@tgsi.net
        ===============
        "Peter van Schie" <vanschie.peter @gmail.com> wrote in message
        news:436b5b7b$0 $11069$e4fe514c @news.xs4all.nl ...[color=blue]
        > Jonathan Crawford wrote:[color=green]
        >> I am niew to pho and am having trouble with dates.
        >>
        >> I can format a date ok
        >> so $today=date('d M Y' )
        >> gives me 2 Nov 2005
        >>
        >>
        >> $dateval is a mysql date
        >> yyyy-mm-dd hh:nn:sss (2005-10-26 13:32:09)
        >> $today=date('d M Y' ,$dateval)
        >> gives me something like 1 july 1970[/color]
        >
        > Hi Jonathan,
        >
        > Try:
        >
        > $today=date('d M Y', strtotime($date val));
        >
        > HTH.
        > Peter.
        >
        > --
        > http://www.phpforums.nl[/color]


        Comment

        • Jonathan Crawford

          #5
          Re: still having problems with dates

          thanks, I will read the manual,
          but sometimes time pressure makes
          that a little difficult.

          I appreciate your effort and actually
          understand it now

          thanks

          jonathan

          --
          ===============
          Jonathan Crawford
          jc@tgsi.net
          ===============
          "Erwin Moller"
          <since_humans_r ead_this_I_am_s pammed_too_much @spamyourself.c om> wrote in
          message news:436b5c22$0 $11070$e4fe514c @news.xs4all.nl ...[color=blue]
          > Jonathan Crawford wrote:
          >[color=green]
          >> Hi
          >>
          >> I am niew to pho and am having trouble with dates.[/color]
          >
          > Read the manual. :-)
          > Really, it is the only things that helps.
          > www.php.net
          >[color=green]
          >>
          >> I can format a date ok
          >> so $today=date('d M Y' )
          >> gives me 2 Nov 2005[/color]
          >
          > which is fine.
          > Except for the fact it is 4 november over here, is your time ok?
          >[color=green]
          >>
          >>
          >> $dateval is a mysql date
          >> yyyy-mm-dd hh:nn:sss (2005-10-26 13:32:09)
          >> $today=date('d M Y' ,$dateval)[/color]
          >
          > And here you go wrong.
          >
          > Did you read what date() does in PHP?
          > Check the manual: It says:
          >
          > -----------------------------------------
          > Description
          > string date ( string format [, int timestamp] )
          > Returns a string formatted according to the given format string using the
          > given integer timestamp or the current local time if no timestamp is
          > given.
          > In other words, timestamp is optional and defaults to the value of
          > time().
          >
          > Note: To generate a timestamp from a string representation of the date,
          > you
          > may be able to use strtotime(). Additionally, some databases have
          > functions
          > to convert their date formats into timestamps (such as MySQL's
          > UNIX_TIMESTAMP function).
          >
          > -----------------------------------------
          >
          > So.....
          >
          > What you should do is:
          > 1) read the manual
          > 2) make sure you know how your date is represented in mySQL, and how PHP
          > wants it. Have a look at strtotime() and the like for help.
          >
          > In general: if a function is not behaving as expected, read the manual and
          > see what is says.
          > On www.php.net: if you cannot find your problem/answer, be sure to read
          > the
          > visitorscomment s too, they often contain usefull information.
          >[color=green]
          >> gives me something like 1 july 1970
          >>
          >> I am not sure how to tell the php that the date is a date.
          >>
          >> It is driving me nuts, and the only particulary
          >> obscure thing I have encountered so far.[/color]
          >
          > rtfm.
          >[color=green]
          >>
          >> i would be grateful for some advice
          >>
          >> thanks
          >>
          >> jonathan
          >>[/color]
          >
          > Good luck!
          >
          > Regards,
          > Erwin Moller[/color]


          Comment

          • Erwin Moller

            #6
            Re: still having problems with dates

            Jonathan Crawford wrote:

            Hi Jonathan,
            [color=blue]
            > thanks, I will read the manual,
            > but sometimes time pressure makes
            > that a little difficult.[/color]

            Yes, I know how it is.
            IMHO:
            Sometimes it is better to tell your boss/client/whatever you will be a week
            later with the project because if you hurry, you will deliver code you
            yourself don't trust.
            Sometimes they even understand that.
            ;-)

            [color=blue]
            >
            > I appreciate your effort and actually[/color]
            understand it now

            Good. :-)

            Good luck with the project!

            Regards,
            Erwin Moller
            [color=blue]
            >
            > thanks
            >
            > jonathan
            >[/color]


            Comment

            Working...