Php calculation time difference php date conversion example

Source: Internet
Author: User
Php calculation time difference php date conversion example

The code for calculating the time difference counts the number of days. I remember that I had seen it in other programs converted to year, month, and day. so I wrote it by hand. In fact, it was quite simple, just a few conversions, however, the monthly statistics are not very accurate, because I don't know how many days it will take to convert it into a month of 30 days, and the error should be small. this cannot be solved.

Example: code for calculating the site creation time: $ jztime site creation time format: 2013-01-01

  1. $ Days = abs (strtotime ($ jztime)-strtotime (date ("Y-m-d")/86400;
  2. If ($ days & gt; 365 ){
  3. $ Site_Y = intval ($ days/365). "Year -";
  4. }
  5. If ($ days> 31 ){
  6. $ Str = explode (".", $ days/365); // obtain the data of more than one year
  7. $ Site_m = ("0.". $ str [(count ($ str)-1)]) * 365/30;
  8. $ Site_m = intval ($ site_m). "month -";
  9. } Bbs.it-home.org
  10. If ($ days> 1 ){
  11. $ Str = explode (".", $ days/365); // continue to obtain the remaining data
  12. $ Site_d = ("0.". $ str [(count ($ str)-1)]) * 365-(intval ($ site_m) * 30 );
  13. $ Site_d = intval ($ site_d). "day ";
  14. }
  15. $ Dayst = $ site_Y. $ site_m. $ site_d;
  16. Echo $ dayst;
  17. ?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.