Luc*_*man 5 php sql forms postgresql
我想将日期插入到我的 pg 数据库中,但我不知道正确的格式是什么,并且 pg 帮助并没有真正帮助。
我的日期格式为 dm-yyyy。因此前导零被省略。
我怎样才能正确插入这个,是否有一个函数可以添加前导零(pg或php)?
检查to_date(text, text)
功能(表9-21包含所有支持的模式):
SELECT to_date('1-9-2011', 'DD-MM-YYYY');
to_date
------------
2011-09-01
(1 row)
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,前导零已正确添加在输出日期中。
INSERT INTO TheTable (the_date) VALUES ('yyyy-mm-dd')
Run Code Online (Sandbox Code Playgroud)
SQL 中的正确顺序是
$psql_str = date('yyyy-mm-dd', date_parse_from_format('d-m-yyyy', $date_str));
Run Code Online (Sandbox Code Playgroud)
将您的格式转换$date_str
为预期的格式。
归档时间: |
|
查看次数: |
13583 次 |
最近记录: |