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


Please Help Members By Posting Answers For Below Questions

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

1076


How to calculate the difference between two dates using php?

1142


What is trait in php?

1065


What is difference between static and final in php?

1107


What is the current stable version of php? What advance thing in php7?

1093


What is the current stable version of php?

1121


What sized websites have you worked on in the past?

1084


What is the difference between htmlentities() and htmlspecialchars()?

1089


Name and explain five of the PHP error constants?

1032


how to detect a mobile device using php

1172


Write a program using while loop?

1115


Tell me what kind of things have you done on the social side?

1063


Explain me is it possible to destroy a cookie?

1025


What does $_files means?

1162


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

1987