0

Hi,

I have this date picker and what i want to do is, how many days, months and years are left from the today's date until the date i chose.

<?php
$secondDate = '2012-08-02'; // date i picked
$currentDate = date('Y-m-d'); //current date

$datechose=explode ('-',$secondDate);
$todaysday=explode ('-',$currentDate);

$daysleft=$datechose[2]-$todaysday[2];
?>

Thank you,
PF2G

3
Contributors
7
Replies
44
Views
3 Years
Discussion Span
Last Post by pritaeas
0

Very easy in MySQL query:
$sql = "SELECT DATEDIFF('2012-08-02','".date('Y-m-d')."')";

Edited by AndrisP

0

can i replace the $dStart with a reult a DatePicker and the $dEnd with date('d-m-Y')

$dStart = new DateTime('2013-03-15');
$dEnd = new DateTime('2013-04-01');
$dDiff = $dStart->diff($dEnd);
echo $dDiff->days;

Like this,

$dStart = $_POST['data_partida'];
$dEnd = date('d-m-Y');
$dDiff = $dStart->diff($dEnd);
echo $dDiff->days;
die;

Thank You,
PF2G

Edited by PF2G

0

can i replace the $dStart with a reult a DatePicker and the $dEnd with date('d-m-Y')

Yes. Just replace the date strings with the variable from the datepicker and the date function:

$date = $_POST['datepicker']; // be sure it's in Y-m-d format
$dStart = new DateTime($date);
$dEnd = new DateTime(date('Y-m-d'));
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.