0

I am trying to get the differences of dates. I am a newbie, please understand. Here are some parts:

(Original Lines)

$BirthDate = "$month $day $year";
$dateBirth = date('F j, Y',strtotime($BirthDate));

These lines are actually working, however, I want to add more info like the hours, minutes, seconds and ante meridiem. I modified the code and here's what I did:

(Modified Lines)

$BirthDate = "$month $day $year $hours $minutes $seconds $ampm";
$dateBirth = date('F j, Y h:i:s a',strtotime($BirthDate));

Yes, the original lines work, the echo the correct inputted data. Problem is, when I did the Modified Lines, the output becomes:

January 1, 1970 08:00:00 am

I can't somehow think of any solution to this. Please help. Thanks.

4

2 回答 2

2

使用\DateTime对象及其差异方法DateTime::dff。程序风格将是date_diff.

手动输入

例子:

<?php
$datetime1 = new DateTime('2009-10-11');
$datetime2 = new DateTime('2009-10-13');
$interval = $datetime1->diff($datetime2);
echo $interval->format('%R%a days');
于 2012-06-28T02:49:36.117 回答
0

也许这会有所帮助

$birth_date = "2006-01-16"; 
$todays_date = date("Y-m-d"); 
$today = strtotime($todays_date); 
$b_date = strtotime($birth_date); 

if ($b_date > $today) { 
    $valid = "yes"; 
} else { 
    $valid = "no"; 
}
于 2012-06-28T02:49:00.293 回答