<tfoot id='OlOdr'></tfoot>
    <i id='OlOdr'><tr id='OlOdr'><dt id='OlOdr'><q id='OlOdr'><span id='OlOdr'><b id='OlOdr'><form id='OlOdr'><ins id='OlOdr'></ins><ul id='OlOdr'></ul><sub id='OlOdr'></sub></form><legend id='OlOdr'></legend><bdo id='OlOdr'><pre id='OlOdr'><center id='OlOdr'></center></pre></bdo></b><th id='OlOdr'></th></span></q></dt></tr></i><div id='OlOdr'><tfoot id='OlOdr'></tfoot><dl id='OlOdr'><fieldset id='OlOdr'></fieldset></dl></div>
      <bdo id='OlOdr'></bdo><ul id='OlOdr'></ul>

      <legend id='OlOdr'><style id='OlOdr'><dir id='OlOdr'><q id='OlOdr'></q></dir></style></legend>

    1. <small id='OlOdr'></small><noframes id='OlOdr'>

        使用 PHP 将日期转换为 SQL 中的 DATETIME

        时间:2023-07-30

            <tbody id='SQESe'></tbody>
          <i id='SQESe'><tr id='SQESe'><dt id='SQESe'><q id='SQESe'><span id='SQESe'><b id='SQESe'><form id='SQESe'><ins id='SQESe'></ins><ul id='SQESe'></ul><sub id='SQESe'></sub></form><legend id='SQESe'></legend><bdo id='SQESe'><pre id='SQESe'><center id='SQESe'></center></pre></bdo></b><th id='SQESe'></th></span></q></dt></tr></i><div id='SQESe'><tfoot id='SQESe'></tfoot><dl id='SQESe'><fieldset id='SQESe'></fieldset></dl></div>
            <legend id='SQESe'><style id='SQESe'><dir id='SQESe'><q id='SQESe'></q></dir></style></legend>
            • <bdo id='SQESe'></bdo><ul id='SQESe'></ul>
                <tfoot id='SQESe'></tfoot>
                • <small id='SQESe'></small><noframes id='SQESe'>

                  本文介绍了使用 PHP 将日期转换为 SQL 中的 DATETIME的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有一个 PHP 论坛,它采用的日期形式为dd/mm/yyyy hh:mm:ss.但是,我需要将其作为 DATETIME 以 yyyy-mm-dd hh:mm:ss 格式插入到 SQL 中.如何转换这些数据?

                  I have a forum in PHP which takes a date like in the form dd/mm/yyyy hh:mm:ss. However, I need to insert it for SQL as a DATETIME in the format as yyyy-mm-dd hh:mm:ss. How can I convert this data?

                  推荐答案

                  您的日期时间格式错误:dd/mm/yyyy hh:mm:ss.可能你的意思是 d/m/Y H:i:s

                  Your date time format is wrong: dd/mm/yyyy hh:mm:ss. Probably you mean d/m/Y H:i:s

                  如果您有 5.3+ 版本,则可以安全地将日期时间转换为另一种格式.举个例子:

                  If you have 5.3+ version there is safe way to convert the date time into another format. Here's an example:

                  $timestamp = '31/05/2001 12:22:56';
                  $timestamp = DateTime::createFromFormat('d/m/Y H:i:s', $timestamp);
                  echo $timestamp->format('Y-m-d H:i:s');
                  

                  或者如果您喜欢更程序化的方式:

                  or if you like more procedural way:

                  $timestamp = '31/05/2001 12:22:56';
                  $timestamp = date_create_from_format('d/m/Y H:i:s', $timestamp);
                  echo date_format($timestamp, 'Y-m-d H:i:s');
                  

                  请注意之前的建议.有些是完全错误的,有些可能会导致错误.

                  Be careful with previous suggestions. Some are completely wrong and others could lead to errors.

                  这篇关于使用 PHP 将日期转换为 SQL 中的 DATETIME的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:需要 mysqli_fetch_all 的替代方案 下一篇:我该如何解决这个“警告:mysqli_connect():(HY000/104

                  相关文章

                  最新文章

                • <small id='G45ct'></small><noframes id='G45ct'>

                  • <bdo id='G45ct'></bdo><ul id='G45ct'></ul>

                  <i id='G45ct'><tr id='G45ct'><dt id='G45ct'><q id='G45ct'><span id='G45ct'><b id='G45ct'><form id='G45ct'><ins id='G45ct'></ins><ul id='G45ct'></ul><sub id='G45ct'></sub></form><legend id='G45ct'></legend><bdo id='G45ct'><pre id='G45ct'><center id='G45ct'></center></pre></bdo></b><th id='G45ct'></th></span></q></dt></tr></i><div id='G45ct'><tfoot id='G45ct'></tfoot><dl id='G45ct'><fieldset id='G45ct'></fieldset></dl></div>
                • <legend id='G45ct'><style id='G45ct'><dir id='G45ct'><q id='G45ct'></q></dir></style></legend>

                      <tfoot id='G45ct'></tfoot>