How to use PHP timestamp

Source: Internet
Author: User
Tags explode
This article mainly share with you the use of PHP timestamp, this article is mainly in the form of code and we share, hope to help everyone.

$date = Date (' y-m-d ', Time ());//Today "2018-3-1"//php get today start timestamp and end timestamp $start = mktime (0, 0, 0, date (' m '), date (' d '), date (' Y ') ); $end = mktime (0, 0, 0, date (' m '), date (' d ') + 1, date (' Y '))-1; resolves the English text datetime to a Unix timestamp: Echo (Strtotime ("Now"). "<br>"), Echo (Strtotime ("October 1980"). "<br>"), Echo (Strtotime ("+5 hours"). "<br>"), Echo (Strtotime ("+1 Week"). "<br>"), Echo (Strtotime ("+1 Week 3 days 7 hours 5 Seconds"). "<br>"), Echo (Strtotime ("Next Monday"). "<br>"); Echo (Strtotime ("Last Sunday"));
$type = $param [' type '];switch ($type) {case 3: {//month $start = mktime (0, 0, 0, date (' m '), 1, date (' Y '));    $end = mktime (0, 0, 0, date (' m '), date (' d ') + 1, date (' Y '));        };    Break        Case 6: {//last month $start = mktime (0, 0, 0, date (' m ')-1, 1, date (' Y '));    $end = mktime (0, 0, 0, date (' m '), 1, date (' Y '))-1;        };    Break        Case 7: {//this week $start = mktime (0, 0, 0, date (' m '), date (' d ')-date (' W '), date (' Y '));    $end = mktime (0, 0, 0, date (' m '), date (' d '), date (' Y '));        };    Break        Case 8: {//last week $start = mktime (0, 0, 0, date (' m '), date (' d ')-7-date (' W '), date (' Y '));    $end = mktime (0, 0, 0, date (' m '), date (' d ')-date (' W '), date (' Y '))-1;        };    Break        Case 4: {//this year $start = mktime (0, 0, 0, 1, 1, date (' Y '));    $end = mktime (0, 0, 0, 1, 1, date (' Y ') + 1);        };    Break        Case 5: {//Yesterday $start = mktime (0, 0, 0, date (' m '), date (' d ')-1, date (' Y ')); $end = mktime (0, 0, 0, date (' m '), date (' d '), date (' Y '))-1;        };    Break        Case 9: {//First seven days $start = mktime (0, 0, 0, date (' m '), date (' d ')-6, date (' Y '));    $end = mktime (Date (' H '), date (' m '), date (' s '), date (' m '), date (' d '), date (' Y '));        };    Break        Case 2: {//First 30 days $start = mktime (0, 0, 0, date (' m '), date (' d ')-, date (' Y '));    $end = mktime (Date (' H '), date (' m '), date (' s '), date (' m '), date (' d '), date (' Y '));        };    Break        Case 1: {//Today $start = mktime (0, 0, 0, date (' m '), date (' d '), date (' Y '));    $end = mktime (0, 0, 0, date (' m '), date (' d ') + 1, date (' Y '))-1;        };    Break    Default: {return '; }}

Using $end and $start as a Where condition

Use the date () method to fetch only the month and date of the current time, but when you query the time format from the database, the method cannot be obtained, for example: date ("D", $time);
But using date () can get to date ("Y", $time), date ("M", $time), date ("D", $time), but if you want to get the current date, we can use the two-time split function
You can do it!

<?php  //time of year  $strtimes = $info [datetime]  $strtimes = Explode ("", $strtime);  $timearray = Explode ("-", $strtimes [0]);  $year = $timearray [0];  $month = $timearray [1];  $day = $timearray [2];    ? >

Related recommendations:

PHP timestamp and date conversion instance sharing

Summary of PHP timestamp function usage

PHP timestamp using instance Code _php tutorial

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.