Home > Backend Development > PHP Tutorial > PHP time format processing method

PHP time format processing method

炎欲天舞
Release: 2023-03-14 16:52:02
Original
2456 people have browsed it

1. Convert the '2016-06-16' format to '20160616'


##

<span style="color: #0000ff"></span><span style="color: #0000ff"><?php<br/>header("Content-type: text/html; charset=utf-8"); <br/>$txDate = &#39;2016-06-16&#39;;<br/>$dateTime = explode(&#39;-&#39;, $txDate);<br/>$Time = $dateTime[0].$dateTime[1].$dateTime[2];<br/>var_dump($Time);<br/><br/>结果:string &#39;20160616&#39; (length=8) <br/>?><br/><br/> $dateTime = explode(&#39;-&#39;, $params[&#39;txDate&#39;]);<br/> $dateTime = $dateTime[&#39;0&#39;].$dateTime[&#39;1&#39;].$dateTime[&#39;2&#39;];   var_dump($dateTime); //20160616<br/></span>
Copy after login

2. By date YYYY-MM-DD Format "

2016-06-16 00:00:00" Query today's content. Need to splice today’s starting time.


<?php
header("Content-type: text/html; charset=utf-8"); 
$txDate = &#39;2016-06-16&#39;;
$dateTime1 = strtotime($txDate);  //int 1466028000 将英文文本日期时间解析为 Unix 时间戳:
$dateTime2= date("Y-m-d H:i:s",$dateTime1); //string &#39;2016-06-16 00:00:00&#39; (length=19)  Date() 函数把时间戳格式化为更易读的日期和时间。

//拼接今日最后时间2016-06-16 23:59:59
$dateTime= date("Y-m-d H:i:s",strtotime(date("Y-m-d",strtotime($dateTime2))."+ 23 hours 59 minutes  59 seconds ")); //string &#39;2016-06-16 23:59:59&#39; (length=19)

$sql = select * form `vvt_user` where userid = 100 AND date_time >= $dateTime2 AND date_time <= $dateTime;
?>
Copy after login

3. Query sql in php to convert the time into unix timestamp for comparison;


$sql .=   &#39; AND UNIX_TIMESTAMP(vvt_repayment.date) >= &#39;.strtotime($day);
$sql .=   &#39; AND UNIX_TIMESTAMP(vvt_repayment.date) <= &#39;.strtotime($endday);
Copy after login

The above is the detailed content of PHP time format processing method. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template