IMAP date

Discussion in 'PHP' started by dreni, Feb 18, 2012.

  1. #1
    The imap code below displays the date like this:
    Sat, 18 Feb 2012 19:22:02 +0100
    I want the date to be displayed like this instead:
    2012-02-18

    Any idea how I can achieve this?

    Thanks in advance

    <?php
    date_default_timezone_set ("Europe/Stockholm");
    /* connect to mail */
    $hostname = '{xxx.xxxx.com:143/notls}INBOX';
    $username = 'xxxxx@xxxxx.com';
    $password = 'xxxxxx';
    
    /* try to connect */
    $inbox = imap_open($hostname,$username,$password) or die('Anslutning till mail misslyckades: ' . imap_last_error());
    
    /* grab emails */
    $emails = imap_search($inbox,'ALL');
    
    /* if emails are returned, cycle through each... */
    if($emails) {
      
      /* begin output var */
      $output = '';
      
      /* put the newest emails on top */
      rsort($emails);
      
      /* for every email... */
      foreach($emails as $email_number) {
        
        /* get information specific to this email */
        $overview = imap_fetch_overview($inbox,$email_number,0);
        $message = imap_fetchbody($inbox,$email_number,2);
        /* output the email header information */
        $output.= '<li>';
        $output.= '<a href="#"><strong>'.$overview[0]->date.'</strong> ';
        $output.= ''.$overview[0]->subject.'<br> ';
        $output.= '<small> Fr&aring;n: '.$overview[0]->from.'</small></a>';
        $output.= '</li>';
        
    
      }
      
      echo $output;
      
    } 
    
    /* close the connection */
    imap_close($inbox);
    
    
    ?>
    Code (markup):
     
    Solved! View solution.
    Last edited: Feb 18, 2012
    dreni, Feb 18, 2012 IP
  2. #2
    Change this:

    
    $output.= '<a href="#"><strong>'.$overview[0]->date.'</strong> ';
    
    PHP:
    To This:

    
    $output.= '<a href="#"><strong>'.date("Y-m-d", strtotime($overview[0]->date)).'</strong> ';
    
    PHP:
     
    ThePHPMaster, Feb 18, 2012 IP
  3. dreni

    dreni Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks ThePHPMaster, you are my hero
     
    dreni, Feb 19, 2012 IP
  4. dreni

    dreni Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    $output.= ''.$overview[0]->subject.'<br> ';
    PHP:
    Do you know how I can truncate this line? So that it only echos 3 words.

    Thanks in advance
     
    dreni, Feb 19, 2012 IP