Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vMbrq-00EZrl-09 for pgsql-general@arkaria.postgresql.org; Sat, 22 Nov 2025 00:52:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vMbro-00AQjD-22 for pgsql-general@arkaria.postgresql.org; Sat, 22 Nov 2025 00:52:44 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vMbro-00AQj4-0y for pgsql-general@lists.postgresql.org; Sat, 22 Nov 2025 00:52:44 +0000 Received: from fhigh-b4-smtp.messagingengine.com ([202.12.124.155]) by makus.postgresql.org with smtp (Exim 4.96) (envelope-from ) id 1vMbrm-000mcM-0i for pgsql-general@postgresql.org; Sat, 22 Nov 2025 00:52:43 +0000 Received: from phl-compute-05.internal (phl-compute-05.internal [10.202.2.45]) by mailfhigh.stl.internal (Postfix) with ESMTP id 0E9977A00A7; Fri, 21 Nov 2025 19:52:42 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Fri, 21 Nov 2025 19:52:42 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1763772761; x=1763859161; bh=YFjiUr8HW4+iG3wmwR6Xkva/R4SswQ2zMzx52ae2gH8=; b= AVd4fbEfo7Dc9Od4/hy7Pd5DqG0fgMUzb3ThuSDrUqLi3lczRDqZpjA5YlF8t4jm WnLBnB51h6rNEvC8hZvAHuRyu7b9FE87mcKTbWwcOKzHZLbxSkdO52h2C+m7BYjS 5JeL2SpYTZk8AUfnmTdzR1S1A2pVh22J6I0tp/vsHAkNzZOQdBPzPo86WSPRVfSy kjRNqPscScfxDLf1x4GOcGuiHwvmlyH5fVobIMkSEJ7RWj6j8SE+Y1F9Vx/Gf/Tv 20wgpg3zjY5M6pSk1C+PIVVBwHePWyC7vvb01V6/ITui+M+xX1AJ9yqDEGcly4BQ 56yJJlc8jNDUpguJXgQM3g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1763772761; x=1763859161; bh=Y FjiUr8HW4+iG3wmwR6Xkva/R4SswQ2zMzx52ae2gH8=; b=h1drcnQQDmGtGF7ma SKq2qfRq8DUm1WO3Ve5jkW8b366HXQPqu65zLzdBMyBucefI69KmTBpIdfP5aUgz tkITslectFZXJPEwdUaeSFIxBYeu/4mUigdskFL7pQLiANY+1TZ/FjV8NpX800zA FoolFyCpX/DVftGpVDoHIF9hRGu9mKtDk72XYOs5DTifFoK4oilR1OxVrxQ8PfCj 8ssn0b59jCWm0snWeJKowJbh56xoNY4gBKWgwKxozLXHBkjaXeA3s3Y4JjunDAmC /+nV2S8qhvirWQIwxBPg35MrzwNn/u49WKMT43xmMFuX7GV+LbZjJLaEdClET3yb w6JIQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggddvfedugeehucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepkfffgggfuffhvfhfjggtgfesthekredttddvjeenucfhrhhomheptegurhhirghn ucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhmqe enucggtffrrghtthgvrhhnpeffffeiueejheehjeeukeehtefgveffvdfhkeegledtfedt teeltddtjedtleehvdenucffohhmrghinhepphhoshhtghhrvghsqhhlrdhorhhgnecuve hluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprggurhhirghn rdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomhdpnhgspghrtghpthhtohepvddpmhhoug gvpehsmhhtphhouhhtpdhrtghpthhtohepshgtrhgrfihfohhrugesphhinhhpohhinhht rhgvshgvrghrtghhrdgtohhmpdhrtghpthhtohepphhgshhqlhdqghgvnhgvrhgrlhesph hoshhtghhrvghsqhhlrdhorhhg X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 21 Nov 2025 19:52:41 -0500 (EST) Message-ID: <438f84e1-52ff-410e-8e33-03029f04927a@aklaver.com> Date: Fri, 21 Nov 2025 16:52:40 -0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Unexpected date conversion results From: Adrian Klaver To: Steve Crawford , PG-General Mailing List References: Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 11/21/25 16:38, Adrian Klaver wrote: > On 11/21/25 16:09, Steve Crawford wrote: >> Either there is a bug in my understanding or one in PostgreSQL. I >> expect a date value to follow the current time zone setting and be >> interpreted as midnight at the start of the given date. In many cases >> it does. Shown below are the postgresql.conf settings and the psql >> client settings showing the time zone to be America/Los_Angeles: >> >> postgresql.conf: >> log_timezone = 'America/Los_Angeles' >> timezone = 'America/Los_Angeles' >> >> Client time zone setting: >> >>     steve=> show timezone; >>            TimeZone >>     --------------------- >>       America/Los_Angeles >> >> > >> However, extracting the epoch from current_date returns 4pm the prior >> day (i.e. 2025-11-21 00:00:00-00), in other words midnight 2025-11-21 >> UTC which seems to be inconsistent behavior: > > > https://www.postgresql.org/docs/current/functions- > datetime.html#FUNCTIONS-DATETIME-EXTRACT > > "epoch > >     For timestamp with time zone values, the number of seconds since > 1970-01-01 00:00:00 UTC (negative for timestamps before that); for date > and timestamp values, the nominal number of seconds since 1970-01-01 > 00:00:00, without regard to timezone or daylight-savings rules; for > interval values, the total number of seconds in the interval > " > > So epoch is in UTC which is confirmed by below. >> >>     steve=> select to_timestamp(extract(epoch from current_date)); >>            to_timestamp >>     ------------------------ >>       2025-11-20 16:00:00-08 > > If you want it to work(I am in  'America/Los_Angeles' also): > > select to_timestamp(extract(epoch from current_date)) at time zone  'UTC'; > >      timezone > --------------------- >  2025-11-21 00:00:00 Or something like: select extract(epoch from current_date); extract ------------ 1763683200 select to_timestamp(extract(epoch from current_date)); to_timestamp ------------------------ 2025-11-20 16:00:00-08 select extract(epoch from current_date::timestamptz); extract ------------------- 1763712000.000000 select to_timestamp(extract(epoch from current_date::timestamptz)); to_timestamp ------------------------ 2025-11-21 00:00:00-08 Where the latter does the rotation to the TimeZone setting via ::timestamptz and you get 28,800 second(8 hr) difference and a returned timestamptz that is correct for the TimeZone. > > >> There was a time, like version 9-dot-something, when the above queries >> performed as expected returning midnight in the current time zone but >> I haven't been able to find a change document indicating this as an >> expected change. > > I don't remember that, but as the gray content of the hair increases the > memory is less solid:) > >> >> -Steve > > -- Adrian Klaver adrian.klaver@aklaver.com