Reputation: 119
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.
Upvotes: 0
Views: 109
Reputation: 11122
Use the \DateTime
object and it's difference method DateTime::dff
. Procedural style would be date_diff
.
Example:
<?php
$datetime1 = new DateTime('2009-10-11');
$datetime2 = new DateTime('2009-10-13');
$interval = $datetime1->diff($datetime2);
echo $interval->format('%R%a days');
Upvotes: 2
Reputation: 4693
maybe this could help
$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";
}
Upvotes: 0