English 中文(简体)
pgSQL : 插入日期格式(领导零)?
原标题:pgSQL : insert date format (leading zeros)?

我想在我的粉碎数据库中添加一个日期,但我只字不提正确的格式,而纸面上的帮助并不真正帮助。

我的日期是用 d式格式写成的。 因此遗漏了零铅。

我怎么能正确插入这一句子,是否有增加铅零的功能(要么是纸面或文件箱)?

最佳回答
INSERT INTO TheTable (the_date) VALUES ( yyyy-mm-dd )

这是Kall的正确命令。

$psql_str = date( yyyy-mm-dd , date_parse_from_format( d-m-yyyy , $date_str));

将<代码> 日期_str改为计算格式。

问题回答

实际上,如果你证实向德国马克(或更好,“ISO,DMY”确定日期,那么你就不必做任何:

postgres=# create table test_table (date_field date);
CREATE TABLE

postgres=# show DateStyle;
 DateStyle 
-----------
 ISO, MDY
(1 row)

postgres=# set DateStyle= ISO, DMY ;
SET

postgres=# insert into test_table (date_field) values ( 2-4-2011 );
INSERT 0 1

postgres=# select * from test_table;
 date_field 
------------
 2011-04-02
(1 row)




相关问题
摘录数据

我如何将Excel板的数据输入我的Django应用? I m将PosgreSQL数据库作为数据库。

Postgres dump of only parts of tables for a dev snapshot

On production our database is a few hundred gigabytes in size. For development and testing, we need to create snapshots of this database that are functionally equivalent, but which are only 10 or 20 ...

How to join attributes in sql select statement?

I want to join few attributes in select statement as one for example select id, (name + + surname + + age) as info from users this doesn t work, how to do it? I m using postgreSQL.

What text encoding to use?

I need to setup my PostgreSQL DB s text encoding to handle non-American English characters that you d find showing up in languages such as German, Spanish, and French. What character encoding should ...

SQL LIKE condition to check for integer?

I am using a set of SQL LIKE conditions to go through the alphabet and list all items beginning with the appropriate letter, e.g. to get all books where the title starts with the letter "A": SELECT * ...

热门标签