SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: help with date

  1. #1
    SitePoint Zealot
    Join Date
    Jun 2010
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    help with date

    hi, I want to replace the date with "0000-00-00" to " ". the code below replaces field regardless
    of value. please advise. thanks
    PHP Code:
    if (str_replace(array('0','-',':'),"000-00-00 00:00") == ''
    {
      
    $row['duedate']='';

    Last edited by cpradio; Feb 26, 2014 at 20:20.

  2. #2
    SitePoint Zealot bronze trophy xMog's Avatar
    Join Date
    Mar 2011
    Posts
    145
    Mentioned
    3 Post(s)
    Tagged
    1 Thread(s)
    Hello!

    I don't really understand your question.
    Here, I rewrote your code so it's more readable:

    Code:
    $searchAr = array('0','-',':');
    $newValue = "000-00-00 00:00";
    if ( str_replace( $searchAr, $newValue ) == '') 
    {
      $row['duedate']='';
    }
    The method definition of str_replace is
    Code:
    mixed str_replace ( mixed $search , mixed $replace , mixed $subject [, int &$count ] )
    Meaning "search the values of $search in $subject and replace it with $replace".

    Your code seems to say "search the values of $searchAr and replace it with $newValue in..."
    I think there is a parameter missing there.. no?
    You want to replace what with what in what?

  3. #3
    SitePoint Zealot
    Join Date
    Jun 2010
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot. Here is my working code:

    $row['duedate'] = preg_replace('/^[0:-]*$/', '', $row['duedate']);

  4. #4
    SitePoint Member
    Join Date
    Mar 2014
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you just forgot something like this
    if(str_replace(array('0','-',':'),' ',$row['duedate'])==' ');
    {
    $row['duedate']='';
    }

  5. #5
    SitePoint Zealot
    Join Date
    Jun 2010
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your help


Bookmarks

Posting Permissions

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