sábado, 20 de mayo de 2017

SUMA DE FECHAS EN JAVASCRIPT Y JQUERY - ADD DATE IN JAVASCRIPT JS AND JQUERY


Una manera fácil de Sumar fechas en javascript, y para hacerlo mas dinámico la entrada de datos con el calendario datepicker que nos proporciona la Libreria Jquery es la siguiente:

An easy way to add dates in javascript, and to make it more dynamic the data entry with the datepicker calendar provided by the Jquery Library is as follows:

veamos el ejemplo. 
Let's see the example: 

 Download the HTML file here : click aqui (suma.html)
Just wait 5 seconds and skip the ad



<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script src="js/jquery.min.js">
</script> <script src="js/jquery-ui.min.js"></script> <link rel="stylesheet" href="css/jquery-ui.css" type="text/css" />
<link rel="stylesheet" href="css/jquery-ui.css" type="text/css" /> </head> <body>
Fecha inicio:<br> <input type="text" id="fecha_inicio" name="fecha_inicio"
placeholder="dd-mm-yyyy" onchange="recalcular_fecha_fin()"/><br /> Fecha fin:<br>
<input type="text" id="fecha_fin" name="fecha_fin"
placeholder="dd-mm-yyyy" />
<script> $(function() { $( "#fecha_inicio" ).datepicker({ dateFormat: 'dd-mm-yy', changeMonth : true, changeYear : true, }); $( "#fecha_fin" ).datepicker({ dateFormat: 'dd-mm-yy', changeMonth : true, changeYear : true, }); }); function recalcular_fecha_fin(){
// Ponemos la fecha var sFecha =$("#fecha_inicio").val(); var aFecha = sFecha.split("-"); var Fecha = new Date(aFecha[2], aFecha[1], aFecha[0]); var dias = 1; //los dias que quieres aumentar Fecha.setTime(Fecha.getTime()+dias*24*60*60*1000);
Fecha=Fecha.getDate()+"-"+Fecha.getMonth()+"-"+Fecha.getFullYear(); $("#fecha_fin").val(Fecha); }
</script> </body> </html>




miércoles, 10 de mayo de 2017

PHP : Obtener la parte entera de un decimal - Get the integer part of a decimal

Encontrar la parte entera de un decimal con PHP es muy simple, solo hay que utilizar la función floor().

Finding the entire part of a decimal with PHP is very simple, just use the function floor().

veamos el ejemplo. Let's see the example: 


<?php

$div = (10/3);
$int = floor($div);
echo "La parte entera es: ".$int;

?>


martes, 9 de mayo de 2017

PHP : Encontrar una fecha en un Array - Find a date in an array

Encontrar la fecha en un array con PHP es muy simple, solo hay que utilizar la función in_array().

veamos el ejemplo. Let's see the example: 



<?php 

$fecha = date('Y-m-d');

$data = array('2017-05-08','2017-05-09','2017-05-10','2017-05-10');

$fechaHoy = '2017-05-09';

if(in_array($fechaHoy, $data)){
echo "FECHA ENCONTRADA";
}else{
echo "FECHA NO EXISTE EN ARRAY";
}

?>

PHP : Sumar o Restar dias a una fecha ( add or subtract days to a date in PHP )

Esta es una manera muy fácil de sumar o restar días a una fecha en PHP, solo hay que utilizar la función strtotime.

This is a very easy way to add or subtract days to a date in PHP, just use the function strtotime.

Veamos el ejemplo. Let's see the example: 


$fecha = date('Y-m-d');
$fechaNueva = strtotime ('+2 day' , strtotime ($fecha));
$fechaNueva = date ('Y-m-d' , $fechaNueva );
echo $fechaNueva ;

Para restar días a la fecha solo hay que agregar el signo menos.
To subtract the days to the date you only have to add the minus sign.

veamos el ejemplo. Let's see the example: 


$fecha = date('Y-m-d');
$fechaNueva = strtotime ('-2 day' , strtotime ($fecha));
$fechaNueva = date ('Y-m-d' , $fechaNueva );
echo $fechaNueva ;