Carbon difference two dates in weeks [duplicate] - php

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);

Related

difference between two dates with format YYYYMMDDTHHiiss [duplicate]

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

How to calculate time difference between two dates [duplicate]

This question already has answers here:
How to calculate the difference between two dates using PHP?
(34 answers)
Closed 7 years ago.
How to Calculate time difference between two dates in php?
$date1=date('Y-m-d H:i:s');
$date2=date('2015-03-06 45:06:03');(Db)
am trying to do once time difference between 2 hours send Mail to user.Current datetime and Db datetime difference between 2 hours mean Send Mail to user.How to Check?
Did you try $diff=$date1 - $dates?
strtotime — Parse about any English textual datetime description into a Unix timestamp and divide by 3600 to find result in hours. Try like this..
$date1=date('Y-m-d H:i:s');
$date2=date('2015-03-06 45:06:03');
echo $diff_hours = (strtotime($date1) - strtotime($date2))/3600;

PHP Convert Date/Time format from 'd/m/Y H:i:s' to 'H:i:s'? [duplicate]

This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 7 years ago.
I have a timestamp column in my database with dates and times formatted like '24/06/2015 14:30', but I need to convert it to just '14:30'. I've tried everything please help.
Very easy to use, just pass in argument and format: http://php.net/manual/en/class.datetime.php

Obtain a month is a few days? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
PHP iterate days of month given month and year
"Obtain all days in month with the number of months"
For example i have date 2011/12/16 this date have months 12(december) now i want with code php know that, This month(12 or december) is a few days?(29? or 31? or 30?)
How is it by PHP?
$mydate = strtotime('2011/12/16');
$daysInMonth = date('t',$mydate);
Edited to add strtotime()

how to compare dates [duplicate]

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);

Categories