This question already has answers here:
How to convert date to timestamp in PHP?
(22 answers)
How to calculate the difference between two dates using PHP?
(34 answers)
Closed 1 year ago.
I have this php code to get the difference between two dates:
$date1=date_create("01.06.2021");
$date2=date_create("05.06.2021");
$diff=date_diff($date1,$date2);
echo $diff->format("%R%a");
Result:
+4
But how can I realize this, wenn the format of $date1 is for example: 20210605T180000
Related
This question already has answers here:
Finding the number of days between two dates
(34 answers)
How to calculate the difference between two dates using PHP?
(34 answers)
Closed 4 months ago.
i am beginner at php. I want to calculate exact total number of days between two dates using php, mysql and want to show it in html form. I tried datediff but it doesn't works as it gives , diffrence not total number of days.
Date fm - 10-10-22;
Date to - 20-10-22;
Total Days - 11
add + 1 to date_diff the output will 11 be like :
<?php
$d1=date_create("2022-10-10");
$d2=date_create("2022-10-20");
$diff=date_diff($d1,$d2);
echo $result = 1 + $diff->format("%R%a days");
?>
php has inbuilt DateTime functions to get the difference. Below outputs 10 day difference.
$date = new DateTime('2022-10-20');
$next_date = new DateTime('2022-10-30');
echo $date->diff($next_date)->days;
This question already has answers here:
Find difference between two datetimes and format at Y-m-d H:i:s
(7 answers)
Closed 5 years ago.
I have a date in this format: '2017-09-26 00:02:37'. I am trying to calculate the difference of this date and now, and get the value in months.
Eg. (52 weeks)
What is the proper way of achieving this?
There is a function in Carbon called diffInWeeks()
$date->diffInWeeks($otherDate);
This question already has answers here:
Adding three months to a date in PHP
(11 answers)
Closed 6 years ago.
There is a start date(let it be 16/02/2016) and months(let it be 3 months) given to me.
how do I calculate the end date?
This will help you
$myDate = "16-02-2016";
$final_date = date('Y-m-d', strtotime("+3 months", strtotime($myDate)));
This question already has answers here:
Convert a date format in PHP [duplicate]
(18 answers)
Closed 7 years ago.
I have date (string):
2015-11-13T15:43:37+01:00
And I want to display this as "Y-m-d H:i:s" format. How to do it?
You can format your date with "date_format()"
http://php.net/manual/en/function.date-format.php
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How to Compare Dates in php?
I have these two dates
1305004066
1305007443
I want to compare which one is later on than other. How can I do that
If it's UNIX timestamps (seconds since 1970-01-01), the largest one is the latest:
$latest = max($time1, $time2);