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
Does php use html?
What is mean tnq
What are the common uses of php?
How can I embed a java program in php file and what changes have to be done in php.ini file?
What is member function?
What is strcmp () in php?
What is the method to execute a php script from the command line?
Are php sessions secure?
What are constructor and destructor in PHP?
How to remove a file?
Why echo is faster than print in php?
When to use get and post request?
How do you count numbers in php?
What are differences between PECL and PEAR?
Write a statement to show the joining of multiple comparisons in php?