PHP Tutorial | Display Days : Hours : Minutes : Seconds Between Two Dates

Опубликовано: 01 Октябрь 2024
на канале: Unpossible POG
6,542
74

Please avoid or flag spams/hateful comments. And do not spam. Enjoy :)

Code Link :
http://unpossiblepog.blogspot.com/201...

Subscribe my Channel:-
http://www.youtube.com/user/SanketRoo...

Facebook Page:-
  / unpossiblens  

Twitter Account:-
  / unpossiblepog  

Blog :-
https://unpossiblepog.blogspot.in/

Hello guys.
This tutorial will be about how to get difference between two dates in days,hours,minutes,seconds format.
Lets start code with a scratch.
You have to call a function str_to_time, make sure to provide date-time format same as in the video.
This function gives the number of seconds of each date.
Now we have to calculate the diffrence.
There are formulas for calculating days, minutes, using seconds.
Make sure you type them as it is.
Now the problem is, single digit doesn’t look good, so we have to convert it using sprintf function.
This function will have two argument, 1st for formatting, and 2nd for value.
I forgot to give zero before 2.
Lets try using different numbers.
All good.
Now 49 hours means, 2 days and 1 hour extra.
So, for that, apply other formulas.
We have to overwrite the hour variable.
You see that, the days are in decimal.
So to make it easy to understand, if days are -ve, then use ceil, and if days are +ve, then use floor.
Lets, test it using different dates.
The code is in the description.
Thank you for watching, dont forget to like share and subscribe.