Note that 3 days may be a lot if you want to create invoices and have to check against a given age to determine if the customer is chargable for taxes and so on. When calculating with the date() function it was more accurate (didn't use seconds/hours for comparison). $birth = new DateTime ( '' ) // three days difference!Įcho $diff -> format ( '%y' ) // will output 44 - correct Here's what I got:Įcho $diff -> format ( '%y' ) // will output 45Įcho $diff -> format ( '%y' ) // will output 45 wrongly I calculated the age gap between now and a birthdate from before 1970 (unix epoch). I found that DateTime::diff isn't as accurate as I thought. Therefore I hope this can help some others: Though I found a number of people who ran into the issue of 5.2 and lower not supporting this function, I was unable to find any solid examples to get around it. Return pluralize ( $interval -> s, 'second' ). If ( $v = $interval -> i >= 1 ) return pluralize ( $interval -> i, 'minute' ). If ( $v = $interval -> h >= 1 ) return pluralize ( $interval -> h, 'hour' ). If ( $v = $interval -> d >= 1 ) return pluralize ( $interval -> d, 'day' ). If ( $v = $interval -> m >= 1 ) return pluralize ( $interval -> m, 'month' ). If ( $v = $interval -> y >= 1 ) return pluralize ( $interval -> y, 'year' ). $suffix = ( $interval -> invert ? ' ago' : '' ) If the date occurs in the past (is negative/inverted), it suffixes it with 'ago'. The function below returns a single number of years, months, days, hours, minutes or seconds between the current date and the provided date. If you want to quickly scan through the resulting intervals, you can use the undocumented properties of DateInterval. Getting Started Introduction A simple tutorial Language Reference Basic syntax Types Variables Constants Expressions Operators Control Structures Functions Classes and Objects Namespaces Errors Exceptions Generators Attributes References Explained Predefined Variables Predefined Exceptions Predefined Interfaces and Classes Context options and parameters Supported Protocols and Wrappers Security Introduction General considerations Installed as CGI binary Installed as an Apache module Session Security Filesystem Security Database Security Error Reporting User Submitted Data Hiding PHP Keeping Current Features HTTP authentication with PHP Cookies Sessions Dealing with XForms Handling file uploads Using remote files Connection handling Persistent Database Connections Command line usage Garbage Collection DTrace Dynamic Tracing Function Reference Affecting PHP's Behaviour Audio Formats Manipulation Authentication Services Command Line Specific Extensions Compression and Archive Extensions Cryptography Extensions Database Extensions Date and Time Related Extensions File System Related Extensions Human Language and Character Encoding Support Image Processing and Generation Mail Related Extensions Mathematical Extensions Non-Text MIME Output Process Control Extensions Other Basic Extensions Other Services Search Engine Extensions Server Specific Extensions Session Extensions Text Processing Variable and Type Related Extensions Web Services Windows Only Extensions XML Manipulation GUI Extensions Keyboard Shortcuts ? This help j Next menu item k Previous menu item g p Previous man page g n Next man page G Scroll to bottom g g Scroll to top g h Goto homepage g s Goto search
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |