-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetting datestyle
57 lines (29 loc) · 1.27 KB
/
setting datestyle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
Way 1 : setting datestyle Per Database Only
show datestyle; show you current date style "ISO, DMY" or "ISO, MDY"
Now depending on what you want in postgres DMY or MDY set in below query
ALTER DATABASE "my_database_name" SET datestyle TO "ISO, DMY";
or
ALTER DATABASE "my_database_name" SET datestyle TO "ISO, MDY";
Most important step : Always after setting datestyle restart postgres
sudo service postgresql restart
Or
sudo /etc/init.d/postgresql restart
Lets test configuration
if you have set DMY below query should work for you
Query:select '20/12/2016'::date Output: "2016-12-20"
Or
if you have set MDY below query should work for you
Query:select '12/19/2016'::date Output: "2016-12-19"
Way 2 : Permanently : whatever you set in config file will be set in all databases you will create in future
In /etc/postgresql/9.3/main/postgresql.conf set
datestyle = 'iso, dmy' OR datestyle = 'iso, mdy'
Most important step : Always after setting datestyle restart postgres
sudo service postgresql restart
Or
sudo /etc/init.d/postgresql restart
Lets test configuration
if you have set DMY below query should work for you
Query:select '20/12/2016'::date Output: "2016-12-20"
Or
if you have set MDY below query should work for you
Query:select '12/19/2016'::date Output: "2016-12-19"