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

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

IF you're using MySQL then it's easier to use:

SELECT DATEDIFF('2012-08-02', NOW())

Yes it's true. Sorry

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

Can someone help me please?

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'));
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.