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
What is mysql_fetch_array?
What is exception handling in php?
Explain what is the difference between $var and $$var?
What is the difference between the functions strstr() and stristr()?
Is php easier than node?
What are the 3 scope levels available in php and how would you define them?
What is a PHP accelerator?
How to download files from an external server with code in php?
Is php easy language to learn?
How does php work?
How a constant is defined in a php script?
Explain scalar type declarations in php7?
Explain what does $_server means?
How to return a value back to the function caller?
How to select a database?