【问题标题】:Date input in codeigniter (d-m-Y)codeigniter 中的日期输入 (d-m-Y)
【发布时间】:2018-11-16 19:53:46
【问题描述】:

我被困在数据库中输入日期。

我已经创建了格式日月年的助手,它的工作。 但我不知道如何使用它在数据库中创建日期。 给我一个视图和控制器的例子。

谢谢!

helper tanggal_helper.php

    if (!function_exists('bulan')) {
        function bulan(){
            $bulan = Date('m');
            switch ($bulan) {
                case 1:
                    $bulan = "Januari";
                    break;
                case 2,3,4,5,6,....12
            }
            return $bulan;
        }
    }


    if (!function_exists('tanggal')) {
        function tanggal() {
            $tanggal = Date('d') . " " .bulan(). " ".Date('Y');
            return $tanggal;
        }
    }

【问题讨论】:

  • 请准确,你的确切问题是什么
  • 我的问题是。我无法在数据库中插入日期格式 d-m-Y
  • 这是因为mysql支持日期格式Y-m-d以这种格式输入日期
  • 我可以更改格式还是什么?因为我需要输入数据“日期”并以 d-m-Y 格式显示数据“数据”
  • 是的,您可以以任何您喜欢的格式显示日期,但要以 Y-m-d 格式存储在 mysql 中转换日期

标签: php mysql codeigniter date


【解决方案1】:

一种解决方案是将列数据类型更改为varchar,然后使用date()strtotime() 插入所需格式的日期

$date = date('d-m-Y', strtotime('now')); // Current date

输出

07-06-2018

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-25
    • 1970-01-01
    相关资源
    最近更新 更多