Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to change the time between php and mysql

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article is to share with you about how to change the time between php and mysql. The editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.

The method of php mysql time conversion: 1, use "FROM_UNIXTIME ()" method in mysql to convert UNIX timestamp into date; 2, use "date ()" function in php to convert UNIX timestamp into date.

This article operating environment: windows7 system, PHP7.1 version, Dell G3 computer.

Programmers who have written PHP+MySQL know that there is a time difference, UNIX timestamp and formatted date are the two time representations we often deal with, Unix timestamp storage, processing is convenient, but not intuitive, formatted date intuitive, but not as easy to deal with as Unix timestamp, so sometimes need to convert each other, the following gives several conversion ways.

1. Finish it in MySQL

This method is converted in the MySQL query statement, the advantage is that it does not occupy the parsing time of the PHP parser, the speed is fast, the disadvantage is that it can only be used in the database query, there are limitations.

1. The function used to convert UNIX timestamp to date: FROM_UNIXTIME ()

General form: select FROM_UNIXTIME (1156219870)

two。 Convert date to UNIX timestamp with function: UNIX_TIMESTAMP ()

General form: Select UNIX_TIMESTAMP ('2006-11-04 12 2300')

For example: the number of records on the day of mysql query:

$sql= "select * from message Where DATE_FORMAT (FROM_UNIXTIME (chattime),'% Ymuri% mmury% d') = DATE_FORMAT (NOW (),'% Ymuri% mmi% d') order by id desc"

Of course, you can also choose to convert in PHP, let's talk about conversion in PHP.

2. Finish it in PHP

This method completes the conversion in the PHP program. The advantage is that the data obtained by the query in the database can be converted, and the conversion range is not limited. The disadvantage is that it takes up the parsing time of the PHP parser, and the speed is relatively slow.

1. The function used to convert UNIX timestamp to date: date ()

General form: date ('Y-m-d Hizuirig slots, 1156219870)

two。 Convert date to UNIX timestamp with function: strtotime ()

General form: strtotime ('2010-03-24 08 1542')

The above is how to convert the time of php and mysql. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report