Skip to content

Instantly share code, notes, and snippets.

View YurePereira's full-sized avatar
😀
Out sick

Yure Pereira YurePereira

😀
Out sick
View GitHub Profile
@YurePereira
YurePereira / sub_interval_date.php
Last active June 19, 2019 14:52
Subtraindo um intervalo de tempo de uma data
<?php
$dateTime = new DateTime('2016-12-01 00:00:01');
echo $dateTime->format('d/m/Y H:i:s') . PHP_EOL;
//Subtraindo 3 anos e 2 meses de nossa data
$dateTime->sub(new DateInterval('P3Y2M'));
echo $dateTime->format('d/m/Y H:i:s');
@YurePereira
YurePereira / using_period_designators.php
Last active June 19, 2019 14:52
Usando Period Designators com DateInterval para alterar datas
<?php
$dateTime = new DateTime('2016-12-01 00:00:01');
echo $dateTime->format('d/m/Y H:i:s'), PHP_EOL;
$dateTime->add(new DateInterval('P1YT10H55S'));
echo $dateTime->format('d/m/Y H:i:s'), PHP_EOL;
$dateTime->sub(new DateInterval('PT5H30M20S'));
echo $dateTime->format('d/m/Y H:i:s'), PHP_EOL;
@YurePereira
YurePereira / using_createfromdatedtring.php
Last active June 19, 2019 14:52
Usando Relative Formats para definir o período do DateInterval para alterar nossas datas
<?php
$dateTime = new DateTime('2016-12-01 00:00:01');
echo $dateTime->format('d/m/Y H:i:s'), PHP_EOL;
//P1YT10H55S
$dateTime->add(DateInterval::createFromDateString('1 year + 10 hours + 55 seconds'));
echo $dateTime->format('d/m/Y H:i:s'), PHP_EOL;
//PT5H30M20S
@YurePereira
YurePereira / using_modify.php
Last active June 19, 2019 14:52
Modificando datas com o métodos modify da classe DateTime
<?php
$dateTime = new DateTime('2016-12-01 00:00:01');
echo $dateTime->format('d/m/Y H:i:s'), PHP_EOL;
//Adiciondo dez dias a nossa data
$dateTime->modify('10 days');
echo $dateTime->format('d/m/Y H:i:s'), PHP_EOL;
//Subtraindo dez dias de nossa data
@YurePereira
YurePereira / using_setdate_and_settime.php
Last active June 19, 2019 14:52
Usando os métodos setDate e setTime para definir datas
<?php
$dateTime = new DateTime();
//Date
$year = 2000; $month = 10; $day = 12;
//Time
$hour = 9; $minute = 1; $second = 10;
$dateTime->setDate($year, $month, $day);
@YurePereira
YurePereira / changes_timezone.php
Created January 15, 2017 16:06
Alterando o TimeZone já definido de uma data utilizando o método setTimeZone da classe DateTime
<?php
$myTimeZone = new DateTimeZone('America/Sao_Paulo');
$myDate = new DateTime('+2 months', $myTimeZone);
echo $myDate->format('Y-m-d H:i:s A') . PHP_EOL;
$myNewTimeZone = new DateTimeZone('Asia/Dubai');
$myDate->setTimezone($myNewTimeZone);
@YurePereira
YurePereira / using_format_dateinterval.php
Created January 20, 2017 03:05
Usando o método Format da classe DateInterval
<?php
$dateTime1 = new DateTime('2016-12-01 12:10:15');
$dateTime2 = new DateTime('2018-01-08 08:18:09');
$interval = $dateTime1->diff($dateTime2);
echo $interval->format('%y anos') . PHP_EOL;
echo $interval->format('%m meses') . PHP_EOL;
echo $interval->format('%d dias') . PHP_EOL;
echo $interval->format('%h horas') . PHP_EOL;
@YurePereira
YurePereira / app.html
Last active February 3, 2017 14:04
AngularJS - Using $rootScope.
<!doctype html>
<html>
<head>
<style type="text/css">
#app {
width: 200px;
padding: 20px;
}
#app .ctrl {
height: 50px;
@YurePereira
YurePereira / create_numeric_array.php
Last active February 7, 2017 13:23
Create a numeric Array in the PHP
<?php
$myNumericArray = array(
100,// Tipo de dado numérico
new DateTime(),// Tipo de dado Object
'String Any',// Tipo de dado String
89,
90
);
@YurePereira
YurePereira / get_first_element_array.php
Created February 7, 2017 14:18
Acessando o primeiro elemento do Array
<?php
$myNumericArray = array(
100,// Tipo de dado numérico
new DateTime(),// Tipo de dado Object
'String Any',// Tipo de dado String
89,
90
);