Displaying a date with strtotime

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

    Displaying a date with strtotime

    I have successfully used strtotime to format the date on a webpage that is
    pulled form a MySQL database in the form yyyy-mm-dd.

    However, in another part of the webpage, I have to insert another date that
    may contain a NULL entry in the database. If I use strtotime to format this
    then it enters the current date, whereas I want it left blank.

    Can anyone help?

    Paul Beckett


  • Pedro Graca

    #2
    Re: Displaying a date with strtotime

    Paul Beckett wrote:[color=blue]
    > However, in another part of the webpage, I have to insert another date that
    > may contain a NULL entry in the database. If I use strtotime to format this
    > then it enters the current date, whereas I want it left blank.[/color]

    <?php
    $x=''; // with $x='2004-01-07'; works as expected

    if ($x) echo date('Y-m-d', strtotime($x));
    else echo 'NULL';
    ?>
    --
    --= my mail box only accepts =--
    --= Content-Type: text/plain =--
    --= Size below 10001 bytes =--

    Comment

    • Tim Van Wassenhove

      #3
      Re: Displaying a date with strtotime

      On 2004-01-07, Paul Beckett <paul_beckett@l ineone.net> wrote:[color=blue]
      > I have successfully used strtotime to format the date on a webpage that is
      > pulled form a MySQL database in the form yyyy-mm-dd.
      >
      > However, in another part of the webpage, I have to insert another date that
      > may contain a NULL entry in the database. If I use strtotime to format this
      > then it enters the current date, whereas I want it left blank.[/color]

      You already posted this question elsewhere. If you really want to post
      it in multiple groups, do it as a crosspost. Because now you are
      multiposting and that is evil. (If you dont know what
      multiposting/crossposting are, use google or something like that to find
      an introduction to usenet netiquette)

      Anyway, you could use the IFNULL function in MySQL.

      As you get the date from MySQL, i don't see why you let MySQL doe the
      date_format instead of using php.



      --

      Comment

      Working...