odnav Posted May 22, 2014 at 11:29 AM Report #556612 Posted May 22, 2014 at 11:29 AM Boas, tenho este código que me diz a diferença entre duas datas, e isto funciona bem, o meu problema é agora somar/subtrair um outro valor retirado também de outro "diff($exemplo)". Como isto vai funcionar tudo em funções diferentes precisava de criar o pedido acima de forma funcional para uma função. Já encontrei alguns assuntos sobre isso, mas queria evitar usar o strtotime Pois não sei funcionar muito bem com ele, e também vi o time_add, mas não me inspira muita confiança. Se me puderem ajudar agradecia. Obrigado <?php function CalculaIntervalo($now,$ref){ $intervalo = $now->diff($ref); $intervalo2=$intervalo->format('%d %h:%i'); echo "</br>".$intervalo2."</br>"; } ?>
HappyHippyHippo Posted May 22, 2014 at 11:58 AM Report #556630 Posted May 22, 2014 at 11:58 AM depois de fazeres os dois diffs poderás adicionar os campos das classes resultantes DataTimeinterval tendo em conta o parâmetro invert IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
odnav Posted May 22, 2014 at 11:59 AM Author Report #556631 Posted May 22, 2014 at 11:59 AM depois de fazeres os dois diffs poderás adicionar os campos das classes resultantes DataTimeinterval tendo em conta o parâmetro invert Podes me arranjar algum exemplo ou link para eu seguir ???
HappyHippyHippo Posted May 22, 2014 at 12:00 PM Report #556633 Posted May 22, 2014 at 12:00 PM http://www.php.net/manual/en/class.dateinterval.php IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
odnav Posted May 22, 2014 at 01:30 PM Author Report #556646 Posted May 22, 2014 at 01:30 PM <?php $now = new DateTime("2014-05-21 18:00:00"); $ref = new DateTime("2014-05-22 01:00:00"); $intervalo = $now->diff($ref); $intervalo2=$intervalo->format('%d %h:%i'); echo "</br>".$intervalo2."</br>"; $nownovo = new DateTime("2014-05-21 18:00:00"); $refnovo = new DateTime("2014-05-22 01:00:00"); $intervalonovo = $nownovo->diff($refnovo); $intervalo2novo=$intervalonovo->format('%d %h:%i'); echo "</br>".$intervalo2novo."</br>"; $resultado=$intervalo2->add($intervalo2novo); $resultado2 = $resultado->format('%d %h:%i'); echo "</br>".$resultado2."</br>"; ?> Ok devo ter usado alguma coisa mal ... :/
odnav Posted May 23, 2014 at 11:51 AM Author Report #556774 Posted May 23, 2014 at 11:51 AM Alguma ajuda??
HappyHippyHippo Posted May 23, 2014 at 12:18 PM Report #556776 Posted May 23, 2014 at 12:18 PM <?php $intervalo2=$intervalo->format('%d %h:%i'); // <--- $intervalo2 é uma string // ... $resultado=$intervalo2->add($intervalo2novo); // <--- que ?? ?> 1 Report IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
odnav Posted May 23, 2014 at 01:56 PM Author Report #556783 Posted May 23, 2014 at 01:56 PM <?php $a = new DateTime(' 00:00:00'); $b = new DateTime(' 18:00:00'); $interval1 = $a->diff($b); //echo "interval 1: ", $interval1->format("%H:%I"), "\n"; $c = new DateTime('00:00:00'); $d = new DateTime('18:00:00'); $interval2 = $c->diff($d); //echo "interval 2: ", $interval2->format("%H:%I"), "\n"; $e = new DateTime('00:00'); $f = clone $e; $e->add($interval1); $e->add($interval2); echo " ", $f->diff($e)->format("%D %H:%I"), " \n"; ?> Finalmente consegui... De uma maneira simples, sem grandes problemas... Não pensei nesta solução... Obrigado 😄
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now