Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
760 views
in Technique[技术] by (71.8m points)

date - PHP Time calculation

Say I have the following 2 dates, a start date and end date:

             Year-Month-Day Hours:Minutes:Seconds  

Start Date:  2010-12-03 14:04:41
Expiry Date: 2010-12-06 12:59:59

How could I, using PHP subtract the two dates and be left with something like:

Difference: -3 days, 2 minutes and 18 seconds (If expiry date is past 3 days for example).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

http://www.php.net/manual/en/datetime.diff.php

<?php
$datetime1 = date_create('2009-10-11');
$datetime2 = date_create('2009-10-13');
$interval = date_diff($datetime1, $datetime2);
echo $interval->format('%R%d days');
//result will be +2 days
?>

I hope that is what you are looking for.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...