Php date and time comparison function

Source: Internet
Author: User
Tags date1 explode

$ Date1 = "2007-10-25 ";
$ Date2 = time ();
Echo "$ date1 compare to $ date2 ";

// 2007-10-25 compare to 1189772448

$ Date1 = "2007-10-25 ";
$ Date2 = date ("y-m-d", time ());
Echo "$ date1 compare to $ date2 ";


/*
You don't know how big the difference between the two dates is. If you want to know this information, it makes sense to convert it to the unix timestamp format. In this case, you have an integer and two dates. Poor computation is a very simple integer. Later, you can convert to minutes, hours, days, or seconds as long as you want.

To use this solution, we need to use the explode () function to help divide the data into smaller date strings. Then, we are all in the date in a separate variable factor, so we can use the mktime () function. This function will work with unix timestamp and return, so we can further calculate
*/

$ Date1 = "2007-10-25 ";
$ Date2 = time ();
$ Datearr = explode ("-", $ date1 );
$ Date1int = mktime (0, 0, $ datearr [1], $ datearr [2], $ datearr [0]);
Echo "$ date1int compare to $ date2 difference is". ($ date1int-$ date2 );

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.