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
Is php 7 backwards compatible?
What is api example?
How long is a php session valid?
What is trait in php?
How to convert strings in hex format?
What is htaccess in php?
What is the Default syntax used in PHP?
What is the difference between $name and $$name?
How can you get the size of an image in PHP?
How to get the length of string?
What is a static method php?
Write a program in php to check whether a number is prime or not?
Explain the three different kinds of Arrays?
How to find a specific value in an array?
Tell me what does the array operator '===' means?