www.webdeveloper.com
Results 1 to 4 of 4

Thread: php date format

  1. #1
    Join Date
    Jun 2012
    Posts
    6

    Smile php date format

    Hi All
    Please advise, using the below code date format but when text field is empty it should not display anything, but instead it gives any date, how can i go around with this.

    echo $Date4 = date("D d-M-y", strtotime($person['om20']));


    waiting for reply.....

  2. #2
    Join Date
    Jan 2007
    Location
    Wisconsin
    Posts
    2,120
    From http://php.net/manual/en/function.strtotime.php
    Returns a timestamp on success, FALSE otherwise.
    From http://www.php.net/manual/en/languag...nteger.casting
    Converting to integer

    To explicitly convert a value to integer, use either the (int) or (integer) casts. However, in most cases the cast is not needed, since a value will be automatically converted if an operator, function or control structure requires an integer argument. A value can also be converted to integer with the intval() function.

    See also: type-juggling.

    From booleans

    FALSE will yield 0 (zero), and TRUE will yield 1 (one).
    So, the functions are behaving exactly as they "should." You just have to perform an explicit test on the field before you assume it's meaningful data in the contexts in which you're using it!

    PHP Code:
    if ($row['field'] == "") {
      
    // don't operate on the field and/or use a default value
    } else {
      
    // operate on the field

    Last edited by svidgen; 06-21-2012 at 12:55 PM.
    Jon Wire

    thepointless.com | rounded corner generator

    I agree with Apple. Flash is just terrible.

    Use CODE tags!

  3. #3
    Join Date
    Apr 2003
    Location
    Rosemount, MN
    Posts
    2,287
    I would revise that to this:

    PHP Code:
    $Date4 "";
    if(!empty(
    $row['field'])) { 
      
    $Date4 date("D d-M-y"strtotime($person['om20']));
    }
    echo 
    $Date4
    My settings

    Browser :: FireFox 1.5
    Resolution :: 1152x864
    Connection :: Cable Modem 2Mbs

  4. #4
    Join Date
    Jun 2012
    Posts
    6

    resolved Thank you, got it

    Thank you, got it

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles