[Recommended] judge whether the function is today/yesterday

Source: Internet
Author: User
Provides various official and user-released code examples. For code reference, you are welcome to exchange and learn [recommended] to determine whether the function is today/yesterday
// ================================================ ========
// This code is not perfect, and there may be some bad points. Please give me some advice!
// Author Zeng Qq839024615 can communicate with me
// ================================================ ========

// When we develop a cms system (your own small system), the development system is not counted for writing templates.
// We sometimes use the data to determine whether today is the data of yesterday, the data of today, and the data of yesterday.
// Etc.

// Today
Function JtColor ($ time ){
Date_default_timezone_set ('Asia/Shanghai ');
$ Jt = strtotime (date ('Y-m-d', time (). '00:00:00 ');
If ($ time> $ jt ){
Return 1; // If yes, 1 is returned.
} Else {
Return 0; // if not, return 0
}
}

// Retrieve from yesterday till now
Function ZtColor ($ time ){
Date_default_timezone_set ('Asia/Shanghai ');
$ Jt = strtotime (date ('Y-m-', time (). (date ('M', time ()-1). '00:00:00 ');
If ($ time> $ jt ){
Return 1; // If yes, 1 is returned.
} Else {
Return 0; // if not, return 0
}
}

// Let's see how we use it.
// If we retrieve a user's message today

$ Is = M ('login')-> order ('time desc')-> find (); // sort by message time
If (JtColor ($ is ['time']) {
Echo "if 1 is returned, the message is sent today ";
} Else {
Echo "if 0 is returned, the last message time is not today, that is, it is not posted after ";
}


// ================================================ ========
// This code is not perfect, and there may be some bad points. Please give me some advice!
// Author Zeng Qq839024615 can communicate with me
// ================================================ ========

AD: truly free, domain name + VM + enterprise mailbox = 0 RMB

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.