Esempio n. 1
0
 public static function getDate($key)
 {
     $value = static::get($key);
     $format = 'Y-m-d';
     $dateObject = DateTime::createfromFormat($format, $value);
     if ($dateObject) {
         return $dateObject->date;
     } else {
         throw new Exception('This must be a valid date. Date format must be Y-m-d');
     }
 }
Esempio n. 2
0
 public static function formatDateTime($out_format, $in_value = null, $in_format = null)
 {
     //  If value is null, current date and time are returned
     if (!empty($out_format)) {
         $in_value = is_string($in_value) || is_null($in_value) ? $in_value : strval($in_value);
         if (!empty($in_format)) {
             if (false === ($date = \DateTime::createfromFormat($in_format, $in_value))) {
                 \Log::error("Failed to format datetime from '{$in_value}'' to '{$in_format}'");
                 return $in_value;
             }
         } else {
             $date = new \DateTime($in_value);
         }
         return $date->format($out_format);
     }
     return $in_value;
 }