Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1a9xCE-0003cP-Ni for pgsql-bugs@arkaria.postgresql.org; Fri, 18 Dec 2015 15:43:54 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1a9xCE-0000kH-6b for pgsql-bugs@arkaria.postgresql.org; Fri, 18 Dec 2015 15:43:54 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1a9xCD-0000k7-Q2 for pgsql-bugs@postgresql.org; Fri, 18 Dec 2015 15:43:53 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1a9xCA-0000ET-IN for pgsql-bugs@postgresql.org; Fri, 18 Dec 2015 15:43:53 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id tBIFhgj1006848; Fri, 18 Dec 2015 10:43:42 -0500 From: Tom Lane To: Andreas Rhode cc: pgsql-bugs@postgresql.org, "Rhode,A.,SNL IT BRIEF,2520,DA, Berater" Subject: Re: to_date() not works as described for pattern DD & HH In-reply-to: <4C903B6A-2FE0-4164-9633-50581F1B58CA@gmx.de> References: <4C903B6A-2FE0-4164-9633-50581F1B58CA@gmx.de> Comments: In-reply-to Andreas Rhode message dated "Fri, 18 Dec 2015 15:25:26 +0100" Date: Fri, 18 Dec 2015 10:43:42 -0500 Message-ID: <6847.1450453422@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org Andreas Rhode writes: > The 2 Pattern DD/HH are not well working > All Digs ar counted from Position6/8 are counted as Days or Hour > and produce a future Date or error from a Timestamp in Milliseconds As far as I can see, the problem here is that you're not giving a pattern that accurately describes the input data. > SELECT to_date('20151202115909001','YYYYMMDD') AS der_2_december_eleven_a_clock > -> "5795177-12-29“ => fare away in the future A correct format for this input would be something like YYYYMMDDHH24MISSMS: # SELECT to_timestamp('20151202115909001','YYYYMMDDHH24MISSMS'); to_timestamp ---------------------------- 2015-12-02 11:59:09.001-05 (1 row) I think what is happening in your example is that it's including all the remaining adjacent digits in the DD field. While this seems silly here, it's less silly in, for example, # SELECT to_date('201512021','YYYYMMDD'); to_date ------------ 2015-12-21 (1 row) But it's not really to_date's job to parse input that is not correctly described by the given format. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs