adspace
How can we know the number of days between two given dates
using PHP?
Answer Posted / sachin
If we know the date format and separator used in dates,
we can separate them out into day, month and year.
e.g.
$d1 = '29-12-1985'; //dd-mm-yyyy
$d2 = '31-12-1985'; //dd-mm-yyyy
$d1_pieces = explode('-',$d1);
$d2_pieces = explode('-',$d2);
$timestamp_d1 =
mktime(0,0,0,$d1_pieces[1],$d1_pieces[0],$d1_pieces[2],);
$timestamp_d2 =
mktime(0,0,0,$d2_pieces[1],$d2_pieces[0],$d2_pieces[2],);
$diff = $d1-$d2;
$num_days = $diff/(24*60*60);
| Is This Answer Correct ? | 3 Yes | 2 No |
Post New Answer View All Answers
How can we extract string "pcds.co.in" from a string "https://info@pcds.co.in" using regular expression of php? More on reg can you explain
How to calculate the difference between two dates using php?
What is trait in php?
What is difference between static and final in php?
What is the current stable version of php? What advance thing in php7?
What is the current stable version of php?
What sized websites have you worked on in the past?
What is the difference between htmlentities() and htmlspecialchars()?
Name and explain five of the PHP error constants?
how to detect a mobile device using php
Write a program using while loop?
Tell me what kind of things have you done on the social side?
Explain me is it possible to destroy a cookie?
What does $_files means?
if you run the app program all vendor open items are cleared but is it possible to reverse the again again open items please tell me the answer