473,804 Members | 3,138 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Bug in function to_char() !!

Hi, i am using PostgreSQL 7.3.2

there's a bug for the date '2005-03-27' !!!!!!!!!!!!!!! !!!!!!!!!!!!

SELECT to_char('2005-03-27'::date,'DD/MM/YYYY');
to_char
------------
26/03/2005
(1 row)

I get the date 26/03/2005 instead of 27/03/2005 !!!

For other dates the function works well !!
Nov 23 '05
14 3530

[root@STIsrv root]# uname -a
Linux STIsrv 2.4.18-14 #1 Wed Sep 4 13:35:50 EDT 2002 i686 i686 i386
GNU/Linux

[root@STIsrv root]# date
Mon Jul 5 13:22:55 EEST 2004

I tried to change the timezone (using timeconfig) i have always:

dragon_devel=# SELECT to_char('2005-03-27'::date,'DD/MM/YY');
to_char
----------
26/03/05
(1 row)

NOTE THAT IF I USE TIMESTAMP IT WORKS::
dragon_devel=# SELECT to_char('2005-03-27'::timestamp, 'DD/MM/YY');
to_char
----------
27/03/05
(1 row)

i am using Red HAt 8.0

I have tried the same command on 2 different servers (same postgres version)

dragon_devel=# SELECT version();
version
----------------------------------------------------------------------------
-----------------------------
PostgreSQL 7.3.2 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.2
20020903 (Red Hat Linux 8.0 3.2-7)
(1 row)
----- Original Message -----
From: "Tom Lane" <tg*@sss.pgh.pa .us>
To: "Najib Abi Fadel" <na*******@usj. edu.lb>
Cc: "generalpos t" <pg***********@ postgresql.org>
Sent: Thursday, July 01, 2004 4:52 PM
Subject: Re: [GENERAL] Bug in function to_char() !!

"Najib Abi Fadel" <na*******@usj. edu.lb> writes:
SELECT to_char('2005-03-27'::date,'DD/MM/YYYY');
to_char
------------
26/03/2005
(1 row)


What timezone setting are you using, and what kind of system is this on?
I suppose that day is a daylight-savings transition day for you, but no
one else is likely to reproduce the problem in a different zone ...

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postg resql.org so that your
message can get through to the mailing list cleanly


---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postg resql.org so that your
message can get through to the mailing list cleanly

Nov 23 '05 #11
"Najib Abi Fadel" <na*******@usj. edu.lb> writes:
I tried to change the timezone (using timeconfig)


You didn't answer the question though: what timezone are you using?

If "SHOW timezone" produces something specific, that is the answer.
If it says "unknown" then what you will need to do is work out
which of the files under /usr/share/zoneinfo is an exact match
for /etc/localtime.

Also, was your Postgres built with --enable-integer-datetimes by
any chance? (Look at the output of pg_config --configure if you
are not sure.)

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postg resql.org

Nov 23 '05 #12
> You didn't answer the question though: what timezone are you using?
Asia/Beirut
If "SHOW timezone" produces something specific, that is the answer.
If it says "unknown" then what you will need to do is work out Show timezone says "unknown" which of the files under /usr/share/zoneinfo is an exact match
for /etc/localtime. I have a file : /usr/share/zoneinfo/Asia/Beirut
Also, was your Postgres built with --enable-integer-datetimes by
any chance? (Look at the output of pg_config --configure if you
are not sure.)

pg_config --configure
'CC=/usr/bin/gcc'

PS : I want just to remember that the to_char(date,'D D/MM/YYYY') works fine
for all dates except the date '2005-03-27'

SELECT to_char('2005-03-27'::date,'DD/MM/YYYY');
to_char
------------
26/03/2005

SELECT to_char('2005-03-20'::date,'DD/MM/YYYY');
to_char
------------
20/03/2005
SELECT to_char('2004-06-07'::date,'DD/MM/YYYY');
to_char
------------
07/06/2004

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 23 '05 #13
"Najib Abi Fadel" <na*******@usj. edu.lb> writes:
You didn't answer the question though: what timezone are you using?
Asia/Beirut


Okay, with that I can reproduce it. That zone is one of the ones where
the DST transitions occur just at midnight. So there really isn't any
"midnight local time" on that date; the first valid local time is 1AM.

The reason to_char() is showing this behavior is there is no
to_char(date) function, only to_char(timesta mp). If you look at what
the implied promotion is doing, you see

regression=> set TimeZone TO 'Asia/Beirut';
SET
regression=> SELECT '2005-03-27'::date::time stamptz;
timestamptz
------------------------
2005-03-26 23:00:00+02
(1 row)

Presented with the invalid local time '2005-03-27 00:00:00', the
timestamp converter chooses to treat it as midnight in the local
daylight-savings time, which is more conventionally written as 11PM
standard time. And then of course your to_char() format only shows
the date part of that.

7.4 and later are more consistent about what is done with "invalid"
local times: they always treat an invalid or ambiguous time as being
local standard time. So in 7.4 and later your example works as
desired:

regression=# set TimeZone TO 'Asia/Beirut';
SET
regression=# SELECT '2005-03-27'::date::time stamptz;
timestamptz
------------------------
2005-03-27 01:00:00+03
(1 row)

"Midnight standard time" is more conventionally 1AM daylight time,
and then you get the right result when looking only at the date part.

Of course this just shifts the locus of pain: if there were any
timezones that switched at 11PM, they'd have funny behavior instead.
But AFAIK there aren't any.

Bottom line: update to 7.4. You could hack around it in 7.3 by
explicitly promoting the date to timestamp without time zone
(or better, make a function to_char(date) to do it for you)
but I think your time would be better spent on an update.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postg resql.org so that your
message can get through to the mailing list cleanly

Nov 23 '05 #14
Bottom line: update to 7.4. You could hack around it in 7.3 by
explicitly promoting the date to timestamp without time zone
(or better, make a function to_char(date) to do it for you)
but I think your time would be better spent on an update.


Since i can't update to 7.4 (for internal reasons),
I created the following function to_char(date,te xt) :
CREATE function to_char(date,te xt) returns text as ' select
to_char($1::tim estamp,$2);' language sql;

It worked well

thx
Najib.

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddres sHere" to ma*******@postg resql.org)

Nov 23 '05 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
18396
by: Praveen | last post by:
Hi All, I have some procedures which written in Oracle. Now the requirement has come to convert those procedures into db2. I used IBM provided MTK tool to convert the procedures. The tool has given the syntax for TO_DATE function. When i tried to execute in db2 command line prompt, it says an error... db2 => select ORA8.TO_DATE(ORA8.TO_CHAR(CURRENT TIMESTAMP , 'mm-dd-yyyy'), 'mm-d
12
9549
by: Newbie | last post by:
how can i call an oracle function to get data without using a select statement or stored procedures? given a project_no, i need to call the function: ops$sqltime.pa_new_job_no_fn which will return the next job_no thanks in advance.
3
2522
by: Wei Wang | last post by:
I get compile error for this code: for i in 1..arg_count-1 LOOP RAISE NOTICE quote_literal(to_char(i, ''9'')); END LOOP; where arg_count = 3. I tried RAISE NOTICE to_char(i, ''9''); as well.
0
1818
by: Ian E. Morgan | last post by:
After being frustrated with the inflexible output of intervals, I've written a pl/pgsql function to do what I want, and hopefully some other people might find it useful. Output is a string that matches the output format of an interval as closely as possible, but rather than counting days as a fixed 24-hours, it recalculates days based on the number of hours in the desired 'day'. For example, this is very useful for summing up work time...
1
16220
by: Hollywood_Jack | last post by:
Peeps, I'm getting an "ORA-00937: not a single group group function error" when I try and run the following query. Any help is appreciated: SELECT tbt.major_cov_cd||', '|| tbt.claim_id||', '|| tbt.accident_date||', '|| tbt.carrier_notified_date||', '|| tbt.accident_date||', '|| tbt.close_date||', '|| tbt.reopen_date||', '||
1
7634
by: rkohon | last post by:
Hello all, I am new to JavaScript and need some ideas, suggestions, or code snippets. I have a form which requires the end user to put in a date for required items. I need javascript function to run on this date supplied by end user and for it to populate another area of the form with the Fiscal Year that this will be needed in. Example: User populates form field with 25-SEPT-07 we need the the Quarter required to immediately poplate...
1
1801
by: holdingbe | last post by:
Hi friends, I need to round or truncate the time.. If 1:24 means i need 1 clock 1:32 means i need 2 clock ... suppose the time in 11:45 PM i need 12:00 am and the time in 11:45 am i need 12:00 pm.. the time should be 12 hours format i write a query in 24 hours SELECT (CASE WHEN SUBSTR(TO_CHAR(SYSDATE,'HH24:MI'),4,5) >=30 THEN SUBSTR(TO_CHAR(SYSDATE,'HH24:MI'),1,2)+1
0
9231
debasisdas
by: debasisdas | last post by:
This function takes 2 dates as parameter and returns the number of working days. You need to add the list of holidays. (I have added a few as sample) CREATE OR REPLACE FUNCTION BUSINESS_DAYS ( i_Date1 IN DATE, i_Date2 IN DATE ) RETURN NUMBER IS
1
3857
by: waraujobh | last post by:
The Oracle function TO_CHAT accept DATE datatype. In DB2, i know that exist the VARCHAR_FORMAT function (synonym TO_CHAR), but this function only accepts TIMESTAMP datatypes. How can i have the same result in DB2, like this SQL in Oracle: SELECT to_char(data_entrada,'YYYYMM') FROM t1 Obs: data_entrada is of datatype DATE. Thanks, Wellerson
0
9579
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10575
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10330
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10076
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7616
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5520
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4297
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3816
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.