Ver Mensaje Individual
  #2  
Antiguo 18-03-2009
Avatar de dec
dec dec is offline
Moderador
 
Registrado: dic 2004
Ubicación: Alcobendas, Madrid, España
Posts: 13.107
Reputación: 34
dec Tiene un aura espectaculardec Tiene un aura espectacular
Hola,

Lo que pasa es que la función "date()" requiere como segundo parámetro una "marca de tiempo" (un "timestamp") y no le vale con la fecha en el formato en que la guarda MySQL, en este caso. Aquí te dejo un par de métodos de cierta clase "DateUtils", que, tal vez puedas aprovechar:

Código PHP:
  /**
   * Decode a datetime MySQL format into an Array.
   *
   * This method decode a datetime in MySQL format into an
   * Array that contain all Year, Month, Day, Hour, Minutes
   * and Seconds in their fields.
   *
   * @static
   * @access public
   * @param $mysqlDatetime String datetime value in MySQL format
   * @return Array Decoded MySQL datetime
   *
   */
  
public static function DecodeMySQLDateTime($mysqlDatetime){
    return array(
      
'year' => (int)substr($mysqlDatetime04),
      
'month' => (int)substr($mysqlDatetime52),
      
'day' => (int)substr($mysqlDatetime82),
      
'hour' => (int)substr($mysqlDatetime112),
      
'minutes' => (int)substr($mysqlDatetime142),
      
'seconds' => (int)substr($mysqlDatetime172)
    );
  }

  
/**
   * Get the UNIX timestamp representation of a MySQL datetime.
   *
   * This method convert a MySQL date time in the UNIX timestamp.
   *
   * @static
   * @access public
   * @param $mySqlDatetime String MySQL datatime to be converted
   * @return Integer UNIX timestamp representation of MySQL the datatime
   *
   */
  
public static function MySQLDatetimeToTimestamp($mySqlDatetime){
    
$d self::DecodeMySQLDateTime($mySqlDatetime);
    if(
is_array($d)){
      return 
mktime($d['hour'], $d['minutes'], $d['seconds'],
                     
$d['month'], $d['day'], $d['year']);
    }else{
      return 
0;
    }
  } 
Una vez tengas el "timestamp" ya sí puedes usar la función "date()".
__________________
David Esperalta
www.decsoftutils.com
Responder Con Cita