SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: IMAP date

  1. #1
    SitePoint Member
    Join Date
    Feb 2012
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question IMAP date

    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

    Code:
    <?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);
    	$date = date('d m Y');
        $swedate = $overview[0]->date;
        /* output the email  information */
        $output.= '<li>';
    	$output.= '<a href="#"><strong>'.$swedate.'</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);
    
    
    ?>

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    PHP Code:
    $swedate date("Y-m-d"strtotime($overview[0]->date)); 
    I think that is what you are looking for.


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
  •