php - Get absolute days away -


i want absolute days away datetime today. example, know if date 2 days away, or 78 days away, or 5,239 days away (not likely, idea). using ms sql database returning datetimes time components 00:00:00.

date_diff returns relative values have crazy math absolute dates calculating months, years, etc.

also, having issues getting date component of today's date in php.

edit: mr. w. ended with:

    $date = $row['airdatedatetime'];     $today = date_create(date("y-m-d"));     $away = date_diff($today, $date);     $d = $away->format("%r%a"); 

the date_create() part part missing convert actual datetime. also, format needs %r%a. using %r%d works dates in month.

the date_diff() function (really, datetime::diff() method) want, , it's not hard. in fact, think example in docs you're after:

<?php     $datetime1 = new datetime('2009-10-11');     $datetime2 = new datetime('2009-10-13');     $interval = $datetime1->diff($datetime2);     echo $interval->format('%r%d days'); ?> 

or

<?php     $datetime1 = date_create('2009-10-11');     $datetime2 = date_create('2009-10-13');     $interval = date_diff($datetime1, $datetime2);     echo $interval->format('%r%d days'); ?> 

what's returned dateinterval object, can format way want format() method. above, it's being formatted days, have ton of options; see http://us.php.net/manual/en/dateinterval.format.php.

you shouldn't need math yourself.

[edit - forgot part]

as getting date component of today's date, can this:

<?php     echo date('y-m-d'); ?> 

see http://us.php.net/manual/en/function.date.php.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -