Skip to content

Instantly share code, notes, and snippets.

@stivenson
Created April 26, 2016 19:43
Show Gist options
  • Save stivenson/ed272266fc9eba0c61536b255150c788 to your computer and use it in GitHub Desktop.
Save stivenson/ed272266fc9eba0c61536b255150c788 to your computer and use it in GitHub Desktop.
Clase para operaciones sobre fechas
<?php
namespace Helpers;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*
*/
/**
* Description of OperationsDate
*
* Dependence for operations on date
*
* @author stivenson
*/
use DateTime;
class OperationsDate {
public function addDaysToCurrentDate($days){
date_default_timezone_set('america/bogota');
$today = new DateTime();
date_add($today, date_interval_create_from_date_string($days.' days'));
return date_format($today, 'Y-m-d');
}
public function addDaysToDate($date,$days){
$date = new DateTime($date);
date_add($date, date_interval_create_from_date_string($days.' days'));
return date_format($date, 'Y-m-d');
}
public function lessDaysToDate($date,$days){
$date = new DateTime($date);
$date->modify("-".$days." days");
return date_format($date, 'Y-m-d');
}
public function statusClient($effective_end_date){
if($effective_end_date == null){ return 4;}
$today = new DateTime();
$datetime_end_date = new DateTime($effective_end_date);
if($datetime_end_date >= $today){
date_add($today, date_interval_create_from_date_string('5 days'));
if($datetime_end_date <= $today){
return 2;
}else{
return 1;
}
}else{
return 3;
}
}
public function ageOfDate($date_birth){
$today = date('Y-m-d');
if(strtotime($today) <= strtotime($date_birth)){
return '( Indique un fecha valida ) ';
}
$diff = abs(strtotime($today) - strtotime($date_birth));
$years = floor($diff / (365*60*60*24));
return $years;
}
public function daysBetween($effective_starting_date,$effective_end_date){
if($effective_end_date == null){ return 0;}
$dias = (strtotime($effective_starting_date)-strtotime($effective_end_date))/86400;
$dias = abs($dias); $dias = floor($dias);
return $dias;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment